Question bank › Backtracking
Dsa Backtracking Warm-up

Combination of K

Given an integer n and an integer k, return all possible combinations of k numbers chosen from the range 1 to n, inclusive. The combinations should be printed in sorted order. Each combination should be on a new line. Input: The input consists of two integers n and k separated by space. Output: The output should contain each combination, sorted lexicographically, each on a new line. Example: Input: 4 2 Output: 1 2 1 3 1 4 2 3 2 4 3 4

Key concepts

backtrackingcombinationsnumbers

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.