Dsa
Recursion
Medium
Generate Combinations of Strings
You are tasked with generating all possible combinations of a string where each character can be included or excluded. The output should be a list of strings, sorted in lexicographical order. Given the input string 'abc', the output should be ['a', 'ab', 'abc', 'ac', 'b', 'bc', 'c']. Note that the empty string is not included in the result. Read the input string from standard input and output the resulting combinations.
Example Input:
abc
Example Output:
a
ab
abc
ac
b
bc
c
Key concepts
recursioncombinationsstrings
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