Ranter
Join devRant
Do all the things like
				++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
				Sign Up
			Pipeless API
				From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
				Learn More
			Comments
		- 
				
				willol13849yA 'valid' combination is when the parenthesis are correctly nested of course
(()()) is valid
(((()) is not - 
				
				()()() ~ 111
()(()) ~ 12
(())() ~ 21
((())) ~ 3
With only nested singletons as above, this is just all the different ways to sum up to the number 3.
This is also this https://en.m.wikipedia.org/wiki/... - 
				
				The answer might be the (N/2)th Bell number for N parens. The 3rd bell number is 5. There are 5 ways to do this for 6 parens.
https://en.m.wikipedia.org/wiki/... - 
				
				willol13849y@thejohnhoffer you might be right ! The interviewer said something about Cathar numbers
 - 
				
				The formal question should be something akin to "Count the rooted trees with N terminal nodes" where N is half the number of parens.
 - 
				
				@willol I can't find cathar numbers online, but I've found a series called the Caley numbers, which don't quite answer this question.
 - 
				
				@matanl
Oh wow, it is the Catalan numbers!
The Bell numbers start
1,1,2,5,15....
The Catalan numbers start
1,1,2,5,14....
For 8 parens (index 4), I spent a long time just now searching for that extra 15th paren grouping. But this makes more sense- there are only 14. Thank you! - 
				
				The key is that the Catalan numbers count the Noncrossing partitions while the Bell numbers count all the partitions.
 - 
				
				
matanl26339y@thejohnhoffer Look at third proof of catalan in wikipedia, I believe you can also get bell numbers subtletly modifying it - 
				
				@matanl It will take me a lot of effort to understand that proof, let alone its relation to Bell numbers, but I do appreciate being pointed in that direction!
 - 
				
				willol13849y@matanl oh yeah, catalan not Cathar! My bad :)
I find it funny how this puzzle seems easy but isn't, at all ! - 
				
				
Root772339yWhy the crap are these puzzles so common in interviews?
If I ran into this problem in a project, I could find an answer pretty quickly using Google. 
Related Rants
- 
						
							
devTea54
Any rubik’s cube fan?
I ordered a rubik’s cube to help me when I faced a bug since I don’t know how to u... - 
						
							
nanhb8Javascript developer interview One of the RH interviewers started asking about myself, personal information,... - 
						
							
Sefie5
Beating https://regexcrossword.com/ felt good.
But I have to admit: I could not beat the last one without bre... 

An interviewer recently asked me "how many 'valid' combinations can you do with N parenthesis, either closing or opening?"
It sounds easy enough, yet I didn't manage to find the solution, apparently I was close enough using dynamic programming. Can you solve it ? :)
undefined
got the job anyway
puzzle