As reported: LinkedIn Software Engineer technical phone screen (USA, Feb 2025): a 5-minute intro, then two questions; passed to the virtual onsite. The first was Valid Parentheses.
Given a string s containing only the characters (, ), {, }, [ and ], return true if it is valid:
- Every open bracket is closed by the same type of bracket.
- Open brackets are closed in the correct order.
- Every close bracket has a corresponding open bracket of the same type.
This is LeetCode 20 — Valid Parentheses.
Example 1
s = "()[]{}"
Output: true
Example 2
s = "(]"
Output: false
Example 3
s = "([)]"
Output: false
Constraints: 1 ≤ s.length ≤ 10^4; s consists of parentheses only: ()[]{}.
Code runner format: LeetCode's test-case format, one JSON value per line (one line per argument). Implement isValid(s); the harness prints true or false.