Sep 042012
 

At a party, everyone shook hands with everybody else. There were 66 handshakes. How many people were there at the party?
Continue reading »

Jun 142012
 

This question is a variation of a question which I posted earlier “Print Permutations of an Array or String“. The code which I had written there will not work if we have repetitions in the array. Today’s post is to write the code to print all permutations and takes care of the case if there is any duplication in the array.

For example: If the array is {1, 2, 3} then the result should be

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

But if the array is {1, 2, 2} then the output should be

1 2 2
2 1 2
2 2 1

Continue reading »