Example 21: Combination of Numbers

Learn how to generate unique combinations of given integers.

Problem

Write a program to generate all unique combinations of 1, 2, and 3 using for loops.

Print the output on the console.

Example

Input Output
1, 2, 3 1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Note: Try to generate unique combinations of the given numbers in the coding widget given below. The order, however, does not matter as it depends on your logic.
If you are unable to do so, check the solution provided in the lesson.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.