Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Not As Hard As It Seems

By Amateur · Limits 1s, 512 MB

Sakib and Shamim are good friends. As Sakib is a little naughty, every night before exam he disturbs Shamim. One day Shamim got an idea to get rid of Sakib. Shamim gave him a sequence of parenthesis and bracket and told him to determine the maximum length of a valid sequence.

For example, [] , ([]) are valid sequence but (] [)(] are not. Remember an empty sequence is also a valid sequence. Since Sakib was intelligent he solved the problem easily and continued disturbing Shamim. Can you solve it too?

You will be given L (the length of the sequence) where L<=10^6 and the sequence will contain at least one character. You have to print the maximum length of a valid sequence.

Sample

InputOutput
[]()
([])()
2
4

Discussion

Statistics


56% Solution Ratio

Fazlerabbi.Earliest, 2w ago

Fazlerabbi.Fastest, 0.0s

Fazlerabbi.Lightest, 0 B

Fazlerabbi.Shortest, 778B

Submit

Login to submit

Related Contests

5th CPU CSE Programming Contest Ended at 2020-03-16 09:00:00 +0000 UTC