Another interesting puzzle:

Parenthesis Permutation

Given N pair of parenthesis. Write an algorithm which would print out all permutations, possible with those parenthesis given that parenthesis are in correct order (i.e. every open parenthesis is matched with closed parenthesis) For .e.g. .. N =3 should give:

()()()

(()())

()(())

(())()

((()))

There are recursive solutions for this you can find just by googling. I thought of a non-recursive solution

Click to view my solution



blog comments powered by Disqus