Check if all subarrays contains at least one unique element | C # program for the above approach ; Function to check if all subarrays of array have at least one unique element ; Stores frequency of subarray elements ; Generate all subarrays ; Insert first element in map ; Update frequency of current subarray in the Dictionary ; Check if at least one element occurs once in current subarray ; If any subarray doesn 't  have unique element ; Clear map for next subarray ; Return Yes if all subarray having at least 1 unique element ; Driver Code ; Given array [ ] arr ; Function Call
using System ; using System . Collections . Generic ; class GFG { static String check ( int [ ] arr , int n ) { Dictionary < int , int > hm = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { hm . Add ( arr [ i ] , 1 ) ; for ( int j = i + 1 ; j < n ; j ++ ) { if ( hm . ContainsKey ( arr [ j ] ) ) hm [ arr [ j ] ] ++ ; else hm . Add ( arr [ j ] , 1 ) ; bool flag = false ; foreach ( int k in hm . Values ) { if ( k == 1 ) { flag = true ; break ; } } if ( ! flag ) return " No " ; } hm . Clear ( ) ; } return " Yes " ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 1 } ; int N = arr . Length ; Console . WriteLine ( check ( arr , N ) ) ; } }