Split the array elements into strictly increasing and decreasing sequence | C # program to implement the above approach ; Function to print both the arrays ; Store both arrays ; Used for hashing ; Iterate for every element ; Increase the Count ; If first occurrence ; If second occurrence ; If occurs more than 2 times ; Sort in increasing order ; Print the increasing array ; Sort ; Print the decreasing array ; Driver code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void PrintBothArrays ( int [ ] a , int n ) { List < int > v1 = new List < int > ( ) ; List < int > v2 = new List < int > ( ) ; Dictionary < int , int > mpp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mpp . ContainsKey ( a [ i ] ) ) mpp [ a [ i ] ] = mpp [ a [ i ] ] + 1 ; else mpp [ a [ i ] ] = 1 ; if ( mpp [ a [ i ] ] == 1 ) v1 . Add ( a [ i ] ) ; else if ( mpp [ a [ i ] ] == 2 ) v2 . Add ( a [ i ] ) ; else { Console . WriteLine ( " Not ▁ possible " ) ; return ; } } v1 . Sort ( ) ; Console . WriteLine ( " Strictly ▁ increasing ▁ array ▁ is : " ) ; for ( int i = 0 ; i < v1 . Count ; i ++ ) Console . Write ( v1 [ i ] + " ▁ " ) ; v2 . Sort ( ) ; v2 . Reverse ( ) ; Console . WriteLine ( " STRNEWLINE Strictly ▁ decreasing ▁ array ▁ is : " ) ; for ( int i = 0 ; i < v2 . Count ; i ++ ) Console . Write ( v2 [ i ] + " ▁ " ) ; } public static void Main ( ) { int [ ] a = { 7 , 2 , 7 , 3 , 3 , 1 , 4 } ; int n = a . Length ; PrintBothArrays ( a , n ) ; } }