Rohancoder's blog

By Rohancoder, history, 18 months ago, In English

Given a string consisting of ()[]{}. Find the length of the longest Balanced Parenthesis in O(N)

  • Vote: I like it
  • -4
  • Vote: I do not like it

| Write comment?
»
18 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

One way to do it is count all the closing and opening parenthesis for each parenthesis and sum up the minimum of opening and closing parenthesis for a given parenthesis.

Edit- Ohk so this case is only valid if the opening comes before the closing one so its not a good solution. It can be done via dp maybe not sure

  • »
    »
    18 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    It's gonna be fine, because string like "))((" is also Balanced Parenthesis

    It's just abount counting brackets