Smallest occurring element in each subsequence | C # program for the above approach ; 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
using System ; using System . Collections . Generic ; class GFG { static void solve ( int [ ] arr , int N ) { Dictionary < int , int > M = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { M . Add ( i , arr [ i ] ) ; } Array . Sort ( arr ) ; Dictionary < int , int > Count = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Count . Add ( arr [ i ] , ( int ) Math . Pow ( 2 , N - i - 1 ) ) ; } foreach ( KeyValuePair < int , int > m in M ) { Console . Write ( Count [ m . Value ] ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 2 , 1 } ; int N = arr . Length ; solve ( arr , N ) ; } }