You are given a sequence of left and right parentheses of length n. Design a data structure which supports operations "toggle the parenthesis at position i" (in time O(log n)) and “report whether the sequence is proper” (in O(1)). (A sequence of parentheses is proper if we never close a parenthesis that wasn't opened previously, as we read the sequence from left to right.)

icon
Related questions
Question
You are given a sequence of left and right parentheses of length n. Design a data structure which supports
operations "toggle the parenthesis at position i" (in time O(log n)) and “report whether the sequence is
proper” (in O(1)). (A sequence of parentheses is proper if we never close a parenthesis that wasn't opened
previously, as we read the sequence from left to right.)
Transcribed Image Text:You are given a sequence of left and right parentheses of length n. Design a data structure which supports operations "toggle the parenthesis at position i" (in time O(log n)) and “report whether the sequence is proper” (in O(1)). (A sequence of parentheses is proper if we never close a parenthesis that wasn't opened previously, as we read the sequence from left to right.)
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer