Print All Subsequences / Power Set
Subsequences Pattern DSA practice problem on Onlearn.
Difficulty: medium.
Topics: Finding all possible subsequences of a string, Strings, Recursion, Backtracking, Bitwise Operations, Time Complexity, Space Complexity, Big O Notation, String Manipulation, bit manipulation, space complexity, dynamic programming, backtracking, recursion, time complexity analysis, Subsequence Problems.
Problem Statement: Given a string s, find and print all its possible non empty subsequences. The output subsequences should be sorted lexicographically. Input Specification: The first and only line contains a string s. Output Specification: Print all non empty subsequences of s, each separated by a space. The subsequences must be sorted lexicographically. Constraints: 1 <= |s| <= 15 The string s consists of lowercase English letters. Sample Test Cases: Example 1: Input: Output: Explanation: Printing all 7 non empty subsequences for the string "abc". Example 2: Input: Output: Explanation: Printing all 3 non empty subsequences for the string "aa". Note that 'a' appears twice because it can be formed from either the first 'a' or the second 'a' of the input string.