Skip to main content

Practice · 5 of 5

Bracket Balance

CHALLENGE
Difficulty: intermediate+25 XP

**Description:** Given a string of '(' and ')' plus q queries, each query replaces one character (given as position and new character). After **each** query print YES if the whole string is balanced, else NO. **Input:** Line 1: the string s (2 <= |s| <= 10^5, even length). Line 2: q (1 <= q <= 10^5). Next q lines: pos c (1 <= pos <= |s|, c is '(' or ')'). **Output:** q lines: YES or NO. **Example:** () / 2 / 1 ( / 1 ) -> NO / YES.

Back to lesson: Practice: STL Problem Set