Loading Now

sequenceFixing

A bracket sequence is called regular if it is possible to insert some numbers and signs into the sequence in such way that the new sequence will represent a correct arithmetic expression.
Given a sequence of brackets ‘(‘ and ‘)’ determine the minimum number of brackets that should be deleted from it in order to get a regular bracket sequence. An empty sequence is also considered regular.

Example

  • s = "()(())" , output sequenceFixing(s) = 0
  • s = "))()((" , output sequenceFixing(s) = 4

Input/Output

  • [execution time limit] 1 seconds (py)

  • [input] string s

    string consisting of symbols ‘(‘ and ‘)’

  • [output] integer

    minimum number of brackets to be deleted

Post Comment

Contact