Check if all subarrays contains at least one unique element | ''Function to check if all subarrays have at least one unique element ; '' Generate all subarray ; ' ' ▁ Store ▁ frequency ▁ of ▁ ▁ subarray ' s elements ; '' Traverse the array over  the range [i, N] ; '' Update frequency of  current subarray in map ; '' Increment count ; '' Decrement count ; '' If all subarrays have at  least 1 unique element ; ''Driver Code ; '' Given array arr[] ; '' Function Call
def check ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT hm = { } NEW_LINE count = 0 NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT hm [ arr [ j ] ] = hm . get ( arr [ j ] , 0 ) + 1 NEW_LINE if ( hm [ arr [ j ] ] == 1 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if ( hm [ arr [ j ] ] == 2 ) : NEW_LINE INDENT count -= 1 NEW_LINE DEDENT if ( count == 0 ) : NEW_LINE INDENT return " No " NEW_LINE DEDENT DEDENT DEDENT return " Yes " NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 1 ] NEW_LINE N = len ( arr ) NEW_LINE print ( check ( arr , N ) ) NEW_LINE DEDENT