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

Continue reading »

Sep 042012

Sep 042012

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

Jun 122012

Print all possible permutations of an Array or a String. For Example: If the array is arr={1, 2, 3}. Then the possible permutations are:

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