Skip to main content
8 of 9
edited tags
casperOne
  • 74.7k
  • 19
  • 190
  • 262

Finding all combinations of well-formed brackets

This came up while talking to a friend and I thought I'd ask here since it's an interesting problem and would like to see other people's solutions.

The task is to write a function Brackets(int n) that prints all combinations of well-formed brackets from 1...n. For Brackets(3) the output would be

() (()) ()() ((())) (()()) (())() ()(()) ()()() 
aleemb
  • 32.2k
  • 21
  • 103
  • 114