Check if all subarrays contains at least one unique element | 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 HashMap ; 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 ; Given array arr [ ] ; Function Call
function check ( arr , n ) { var hm = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { hm . set ( arr [ i ] , 1 ) ; for ( var j = i + 1 ; j < n ; j ++ ) { if ( hm . has ( arr [ j ] ) ) hm . set ( arr [ j ] , hm . get ( arr [ j ] ) + 1 ) ; else hm . set ( arr [ j ] , 1 ) var flag = false ; hm . forEach ( ( value , key ) => { if ( value == 1 ) { flag = true ; } } ) ; if ( ! flag ) return " " ; } hm = new Map ( ) ; } return " " ; } var arr = [ 1 , 2 , 1 ] ; var N = arr . length ; document . write ( check ( arr , N ) ) ;