-
-
Save anonymous/3db015403c07f56e7d0ce9053aeb18e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Complete the function below. | |
*/ | |
function balancedOrNot(expressions, maxReplacements) { | |
var arrayLength = expressions.length; | |
var res = Array(arrayLength).fill(1); | |
for(var i = 0; i < arrayLength; i++) | |
{ | |
var stringLength = expressions[i].length; | |
var checkString = expressions[i]; | |
var replacementCount = maxReplacements[i]; | |
var openCount = 0; | |
for(var j = 0; j < stringLength; j++) | |
{ | |
if (checkString[j] === '<') | |
{ | |
openCount += 1; | |
} | |
if (checkString[j] === '>') | |
{ | |
if(openCount > 0) | |
{ | |
openCount -= 1; | |
} | |
else if (replacementCount > 0) | |
{ | |
replacementCount -= 1; | |
} | |
else if (replacementCount === 0) | |
{ | |
res[i] = 0; | |
} | |
} | |
} | |
if(openCount > 0) | |
{ | |
res[i] = 0; | |
} | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment