Smallest occurring element in each subsequence | Function that count the subsequence such that each element as the minimum element in the subsequence ; Store index in a map ; Sort the array ; To store count of subsequence ; Traverse the array ; Store count of subsequence ; Print the count of subsequence ; Driver code ; Function call
def solve ( arr , N ) : NEW_LINE INDENT M = { } NEW_LINE for i in range ( N ) : NEW_LINE INDENT M [ i ] = arr [ i ] NEW_LINE DEDENT arr . sort ( ) NEW_LINE Count = { } NEW_LINE for i in range ( N ) : NEW_LINE INDENT Count [ arr [ i ] ] = pow ( 2 , N - i - 1 ) NEW_LINE DEDENT for it in Count . values ( ) : NEW_LINE INDENT print ( it , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 5 , 2 , 1 ] NEW_LINE N = len ( arr ) NEW_LINE solve ( arr , N ) NEW_LINE DEDENT