Monday, September 27, 2010

catalon number

In how many different ways can you put brackets properly using only curly braces only for n times?
For eg:
If n = 1 => {} Only 1 is possible
If n = 2 => {}{}, {{}} 2 are possible


Answer: Use catalon number c(2n n)n/(n+1).

How to shuffle array

How to shuffle array?.

Also, how will you shuffle if array size is not known, i mean it can stream of numbers.

How to add two linked list

How to add two linked list where each list is a list of numbers like 1 -> 2 -> 3 -> 4 .
You should not use recursion or reversing the list.

Note: Two lists can differ by size.