We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Could anyone please tell what i am doing wrong in this code. 3 test cases are failing -
functionisBalanced(s){// Write your code hereif(!s||s==""){return"NO"}letarr=s.split("");letarrLength=arr.length;if((arrLength%2)!=0){return"NO"}letbracketsObj={"(":")","{":"}","[":"]"};letclosingBrackets=Object.values(bracketsObj);lettempArray=[];for(leti=0;i<arrLength;i++){letisMatched=false;if(closingBrackets.includes(arr[i])){if(bracketsObj[tempArray.pop()]!=arr[i]){return"NO";}}else{tempArray.push(arr[i]);}}return"YES"}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
Could anyone please tell what i am doing wrong in this code. 3 test cases are failing -