Brackets

Good day! In this post we will attempt to solve the Brackets problem from Codility_.

A string S consisting of N characters is considered to be properly nested if any of the following conditions is true:

o S is empty;
o S has the form "(U)" or "[U]" or "{U}" where U is a properly nested string;
o S has the form "VW" where V and W are properly nested strings.

For example, the string "{[()()]}" is properly nested but "([)()]" is not.

Write a function such that given a string S consisting of N characters, 
returns 1 if S is properly nested and 0 otherwise.

Write an efficient algorithm for the following assumptions:

o N is an integer within the range [0..200,000];
o string S consists only of the following characters: "(", "{", "[", "]", "}" and/or ")".

We are presented with a string. We need to determine if the different types of brackets match. If interested in this problem I suggest you read the current and full description at Codility_. Continue reading “Brackets”