As reported: LinkedIn Software Engineer (Jul 2025) phone screen, the second question: valid parentheses in a string that also contains letters, with the examples below; follow-up in
O(1)space.
Given a string s of letters and the characters ( and ), return true if its parentheses are balanced: every ( is closed by a later ), every ) closes an earlier (, and pairs nest properly. Letters are ignored.
Example 1
s = "((AbNC)())"
Output: true
Example 2
s = "()(NFJDH)(()"
Output: false (the last "(" is never closed)
Constraints: 0 ≤ s.length ≤ 10^5; s contains only English letters, ( and ).
Code runner format: one JSON line: s. Implement isBalanced(s); the harness prints true or false.
Follow-ups
- Solve it in
O(1)extra space.