Compute Minimum Parentheses Additions
Company: Bytedance
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates proficiency in string processing and algorithmic reasoning for balancing parentheses, testing understanding of invariants and edge-case handling.
Constraints
- s contains only '(' and ')'
Examples
Input: ('()))((',)
Expected Output: 4
Explanation: Given example.
Input: ('',)
Expected Output: 0
Explanation: Empty string is already valid.
Input: ('(((',)
Expected Output: 3
Explanation: Needs closing parentheses.
Input: (')))',)
Expected Output: 3
Explanation: Needs opening parentheses.
Input: ('()()',)
Expected Output: 0
Explanation: Already valid.
Hints
- Count unmatched closing parentheses and unmatched openings.