Skip to content

Commit

Permalink
Create 1963-minimum-number-of-swaps-to-make-the-string-balanced.c
Browse files Browse the repository at this point in the history
Create the C solution as the same solution in the YouTube video "https://www.youtube.com/watch?v=3YDBT9ZrfaU"
  • Loading branch information
MHamiid authored Jan 20, 2023
1 parent a93ccfe commit c56ebe5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions c/1963-minimum-number-of-swaps-to-make-the-string-balanced.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#define max(x, y) ((x) > (y) ? (x) : (y))

int minSwaps(char * s){
int extraClosingBrackets = 0;
int maxExtraClosingBrackets = 0;
size_t sLen = strlen(s);

for(size_t i = 0; i < sLen; i++)
{
if(s[i] == ']')
{
extraClosingBrackets += 1;
}
else
{
extraClosingBrackets -= 1;
}

maxExtraClosingBrackets = max(maxExtraClosingBrackets, extraClosingBrackets);
}

return (maxExtraClosingBrackets + 1) / 2;
}

0 comments on commit c56ebe5

Please sign in to comment.