Dsa
Recursion
Hard
Combination of K Characters
Given a string of unique characters and an integer k, write a program to generate all combinations of k characters from the string. Each combination should be printed as a space-separated list of characters on a new line. The input consists of a line with the string s (1 ≤ |s| ≤ 10) followed by an integer k (1 ≤ k ≤ |s|). Print each combination in lexicographical order.
Example:
Input:
abcd
2
Output:
a b
a c
a d
b c
b d
c d
Key concepts
recursioncombinatoricsbacktracking
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