Skip to content

Instantly share code, notes, and snippets.

@misterpoloy
Created October 7, 2021 21:21
Show Gist options
  • Save misterpoloy/7ea1421d3861a8ad3ae531b5f8ec260c to your computer and use it in GitHub Desktop.
Save misterpoloy/7ea1421d3861a8ad3ae531b5f8ec260c to your computer and use it in GitHub Desktop.
Min number of swaps greedy
var minSwaps = function(s) {
let close = 0
let maxClose = 0
for (const letter of s.split('')) {
if (letter == "[") {
close -= 1
} else {
close += 1
}
maxClose = Math.max(maxClose, close)
}
return Math.floor((maxClose + 1) / 2)
};
@misterpoloy
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment