Problems
Problem - Closed Parens
For a given string composed of (){}[]
it is valid if each open paren [({
has an associated closing bracket.
Example
// '[]' true// '[}]' false// '[()]' true
Solution
/*** @param {*} v a sting composed of '[]{}()` chars*/function isValid(v) {/*** time: O(n)* space: O(n)*/const stack = []const sArr = v.split("")for (s in sArr) {if (sArr[s] in key) {stack.push(sArr[s])} else {if (stack.length < 1) {return false}const open = stack.pop()if (sArr[s] !== key[open]) {return false}}}return stack.length < 1}
Remove Duplicates from Sorted Array
In place implies not creating another array.