Write a Program to determine Valid Parentheses

# 20. Valid Parentheses

Given a string s containing just 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.
Every close bracket has a corresponding open bracket of the same type.

### Example 1:
```
Input: s = "()"
Output: true
```
### Example 2:
```
Input: s = "()[]{}"
Output: true
 ```
Constraints:
```
1 <= s.length <= 104
s consists of parentheses only '()[]{}'.
```
/**
 * @param {string} s
 * @return {boolean}
 */
const isValid = function(s) {
    const stack = [];
    const mapObj = new Map([
        [')', '('],
        ['}', '{'],
        [']', '[']
    ]);
    for(let i = 0; i < s.length; i++){
        if (mapObj.has(s[i])) {
            if(stack.length > 0 && stack.at(-1) === mapObj.get(s[i])) {
                stack.pop();
            } else {
                return false;
            }
        } else {
            stack.push(s[i]);
        }
    }
    return stack.length == 0;
};