Example
Array : {1, 34, 42, 34, 42, 34}
If we delete all 1s and 42s from the above array : 3 deletes
If we delete all 1s and 34s from the above array : 4 deletes
If we delete all 34s and 42s from the above array : 5 deletes
In each of the above cases we end up with equal numbers in the array. Therefore, minimum required deletes = 3.
int getMinimumDeletes( vector<int> &elements )
{
// Implement this
}
Example
Array : { ‘a’, ‘b’ }, k = 3
Output
aaa
aab
aba
abb
baa
bab
bba
bbb
void printAllStrings( vector<char> &letters, int k )
{
// Print all possible strings
}
Example:
If S = {1,2,3}Then the output should be:
[]
[1]
[1,2]
[1,2,3]
[1,3]
[2]
[2,3]
[3]
void printAllSubsets( vector<int> &elements )
{
// Print all the subsets of the given array
}
i.e. disk 1 on the top and disk N at the bottom.
Your one move will consist of picking the upper disk from one of the rods and placing it on top of another rod. i.e.
Disk i: From Rod1 to Rod2
A disk can only be moved if it is the uppermost disk on a rod.
Also, you cannot place a larger disk on the top of a smaller disk.
You have to print a series of such moves to transfer all the disks from from_rod to to_rod. You may use aux_rod for intermediate steps.
You can also see the animation of the puzzle:
Source: Wikipedia
Example:
Let us suppose there are 2 disks and the rods are:
Disk 1: From A to C
Disk 2: From A to B
Disk 3: From C to B
void towerOfHanoi(int num_of_disks, string from_rod, string to_rod, string aux_rod){
// Print required series of moves to solve the puzzle
}