Meta Coding Interview: Unmatched Parentheses Finder

Based on questions reported for Meta interviews

The interviewer opens

Hi, and thanks for joining. Welcome to your interview for the software engineer role at Meta. We'll work through a coding problem together, so please think out loud as you code. If you need to step out or take a break, you can pause the interview anytime with the Pause button at the top right.

The problem is about flagging parentheses that have no partner in user text, and it's in the Problem tab on the right. Take your time reading it through, and let me know if you have any questions before you start.

The problem

A comment-rendering pipeline must flag parentheses in user text that have no partner.

  • s: a string of lowercase letters, ( and ).

Scan left to right. Each ) pairs with the closest earlier ( that is not already paired. A ) with no available ( is unmatched, and every ( still unpaired at the end is unmatched. Letters are never unmatched. Return the indices of all unmatched parentheses in ascending order.

Example: s = "a)b(c)d(" → [1, 7]

0 ≤ len(s) ≤ 10^5.