• + 3 comments

    Something must be wrong with the compiler, or something is happening behind the scenes. I have some code that is failing 3 cases, but when I unlock the test case and run the input as a custom case it passes just fine.

    (I have a correct solution already, but my friend wanted me to try out this other solution)

     const stack = [];
        let i = 0;
        while (i <= s.length) {
            switch (s[i]) {
                case "(": 
                case "[": 
                case "{": 
                    stack.push(s[i]); 
                    break;
                case ")": 
                    if (stack.pop() !== "(") return "NO"; 
                    break;
                case ']': 
                    if (stack.pop() !== "[") return "NO"; 
                    break;
                case '}': 
                    if (stack.pop() !== "{") return "NO";
                    break;
            }
    												
    												
            i++
        }
    												return "YES"