Sudo Placement | Special Subsequences | Python3 program to find all special subsequences of the given type ; Function to generate the required subsequences ; If the index pointer has reached the end of input string ; Skip empty ( " ▁ " ) subsequence ; Exclude current character in output string ; Include current character in output string ; Remove the current included character and and include it in its uppercase form ; Function to print the required subsequences ; Output String to store every subsequence ; Set of strings that will store all special subsequences in lexicographical sorted order ; Sort the strings to print in sorted order ; Driver Code
from typing import List NEW_LINE def generateSubsequences ( input : str , output : str , idx : int , ans : List [ str ] ) -> None : NEW_LINE INDENT if idx == len ( input ) : NEW_LINE INDENT if ( len ( output ) ) : NEW_LINE INDENT ans . append ( output ) NEW_LINE DEDENT return NEW_LINE DEDENT generateSubsequences ( input , output , idx + 1 , ans ) NEW_LINE output += input [ idx ] NEW_LINE generateSubsequences ( input , output , idx + 1 , ans ) NEW_LINE output = output [ : - 1 ] NEW_LINE upper = input [ idx ] NEW_LINE upper = upper . upper ( ) NEW_LINE output += upper NEW_LINE generateSubsequences ( input , output , idx + 1 , ans ) NEW_LINE DEDENT def printSubsequences ( S : str ) -> None : NEW_LINE INDENT output = " " NEW_LINE ans = [ ] NEW_LINE generateSubsequences ( S , output , 0 , ans ) NEW_LINE ans . sort ( ) NEW_LINE for string in ans : NEW_LINE INDENT print ( string , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = " ab " NEW_LINE printSubsequences ( S ) NEW_LINE DEDENT