Skip to main content
1 of 14
J.Doe
  • 2.6k
  • 11
  • 15

R, 134 bytes

This recursive approach is probably not the shortest way to do it, but it was fun to code up.

f=function(n,b=c("(",")"),x=b){if(!n)return(Reduce(paste0,x));sort(unique(unlist(sapply(0:(n+1),function(i)f(n-1,x=append(b,x,i))))))}

Try it online!

J.Doe
  • 2.6k
  • 11
  • 15