Created
February 22, 2017 13:08
-
-
Save abhinavnigam2207/f6df6e8a1d95f248edb7762360d9d901 to your computer and use it in GitHub Desktop.
Bracket Problem (Asked in Toptal Interview )
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
'use strict'; | |
function solution(S) { | |
var arr = []; | |
var K = 0; | |
for (var i=0; i<S.length; i++) { | |
if (S[i]=='(') { | |
arr.push(S[i]); | |
} else { | |
if(arr.length){ | |
arr.pop(); | |
} | |
K++; | |
} | |
} | |
return K; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi abhinav,
Thanks for sharing. what were the other two problems? I am preparing for Toptal. I would like to know the difficulty level of problems asked