Data structure problem 2 (Stack): Valid Parentheses problem.

This is one of the interview questions asked in the technical or data structure round which can be solved using stack. As we know stack is first in last out . You may also like this: Data structure problem 1. So let's begin with the problem statement, 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 = []; //As javascript array behaves like stack for ( let i = 0 ; i < s.length; i ++ ) { if (s[i