Coding Interview Questions set 5

Let's begin with set 5, Q11)Valid Parentheses problem. Given a string s containing only the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Examples : a)Input: s = "()" Output: true Example 2: b)Input: s = "()[]{}" Output: true Example 3: c)Input: s = "(]" Output: false Solution: var isValid = function(s) { const obj={ "}":"{", "]":"[", ")":"(", }, var stack=[]; for(let i=0;i<s.length;i++){ if(s[i] in obj) { if(!stack.length || stack[stack.length-1]!==obj[s[i]]) { return false; } else stack.pop(); }else stack.push(s[i]); } return !stack.length; }; L