Current Size:
Chakra BreakPoints
base0px
sm480px
md768px
lg992px
xl1280px
2xl1536px
Current Height:Width
widthpx
heightpx

Subjects

Dev Problems 2022

Date Created: 2021/03/15

Last Update: 2022/12/14

#algorithms #notes

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.

References

LeetCode

More Notes

All Notes
HomeProjects

Links

Home Articles Notes Projects About Style Guide Site Credits

Contact

 [email protected]

Location

🌎 Earth