Print all the possible permutations by adding X and Y (Hacker Rank Interview Question)

Input:
X and Y are integer values, where X < Y
N is the length of permutation
Output:
To print all the possible permutations in sorted order, in given form, starting from zero.

i.e 0 , 0 + X (or Y)

For example:
X = 1, Y = 2
N = 3.

output should be:
0 1 2
0 1 3
0 2 3
0 2 4

To solve this problem, we can use recursion by passing the value of X and Y with the current state array.
At each recursion step, we will call the method by passing values of X or Y in order. The end of the recursion would be the length of array reaching the value of N.

Here is the code:

You can also clone the repository from GIT using the link below:

GitHub-Mark-32px https://github.com/Niravkumar-Patel/SnippetExampleRepo.git

HackerRankProjectStructure

The output of above code:

You can also clone the repository from GIT using the link below:

GitHub-Mark-32px https://github.com/Niravkumar-Patel/SnippetExampleRepo.git

Leave a Reply

Your email address will not be published. Required fields are marked *