All possible permutations of enum

I was asked this in Amazon interview:
Given enums: enum MyType { Red, Green, Blue, …, LastColor };

and a function for unit testing.
enum MyType { Red, Green, Blue, …, LastColor };// Assume K enums

Assume a function like :
int MyFunc(MyType[] args) { /implementation/}
This means it can take n aruguments.
We have to write a test function which generated all permutations of enums.

So this becomes I guess generate all possible permutations from K enums of length N

I gave the answer with recursion and backtracking.
They wanted better than recursion including backtracking because recursion can take a lot of memory.

I gave:

Let's assume we have k enums and N parameters to the function.

So, taking an example: if k is 4 (values 0,1,2,3) and N is 2, we will have the following combinations
00
01
02
03
10
11
12
13
..
33
Total of 16 combinations. This gives the general formula of number of possible combinations to be k^n.
Now, if we see more closely we are basically printing decimal numbers ranging 0 to 15 from to the base k ( k = 4 in this case).
So, the algorithm looks like this
Iterate for i, i ranging from 0 to (k^N)
Use a helper function to convert i to base k and then print that in the loop.
This would give us the list of all the posible function parameters.
Please let me know if you need any more information.

They wanted to implement the following functions without recusrion:

enum MyType { Red, Green, Blue,, LastColor };
int MyFunc(MyType[] args) { /*implementation*/}

With the above, it would be great if you could articulate the end-to-end permutation generation pseudocode. Something like filling in the pseudo code in ??? and comments below:

??? GenerateParams(???)
{
}

bool ValidateMyFunc()
{
    // Iterate over all permutation
       // GenerateParams
       // Call MyFunc with the generates params
}

Please advice me in implementing these methods using base conversion.

Comments (1)