Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1536 from aadil42/patch-30
Browse files Browse the repository at this point in the history
Create 1963-minimum-number-of-swaps-to-make-the-string-balanced.js
  • Loading branch information
Ahmad-A0 authored Dec 22, 2022
2 parents d5c4c9d + 1a89764 commit 8f07bb2
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// problem link https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced
// time complexity O(n)
// space complexity O(1)

var minSwaps = function(s) {

let extraClosing = 0;
let maxClosing = 0;
for(let i = 0; i < s.length; i++) {
s[i] === ']' ? extraClosing++ : extraClosing--;
maxClosing = Math.max(maxClosing, extraClosing);
}

return Math.ceil(maxClosing/2);
};

0 comments on commit 8f07bb2

Please sign in to comment.