How can I generate permutations given the following conditions?
- There are two integers, for ex. 1 and 4.
- The two integers given will be part of the permutation where each integer will appear at most N times and the size of each permutation is K.
So let's say for N = 3 and K = 5, so the correct result should be:
{1, 1, 1, 4, 4} , {1, 1, 4, 1, 4} , {4, 4, 4, 1, 1} , etc..
The following are example of invalid or incorrect results:
{1, 1, 1, 1, 4} -> 1 appear 4 times (1 should appear not greater than 3 times)
{1, 4, 4, 4, 1, 1} -> the size of the list is 6 (the size should be exactly 5)
Also, each permutation should be unique, meaning no duplicates.
I hope I can get the best solution or algorithm for this problem.
Thanks in advance. :)