Difference of count of distinct elements present to left and right for each array element | Function to find the difference of count of distince elements to the left and right for each array elements ; Stores distinct array element in the left and right ; Traverse the array ; Insert all element to the left in the set S1 ; Insert all element to the right in the set S2 ; Print the difference ; Driver Code
def findDifferenceArray ( arr , N ) : NEW_LINE INDENT S1 = set ( ) ; NEW_LINE S2 = set ( ) ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i ) : NEW_LINE INDENT S1 . add ( arr [ j ] ) ; NEW_LINE DEDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT S2 . add ( arr [ j ] ) ; NEW_LINE DEDENT print ( abs ( len ( S1 ) - len ( S2 ) ) , end = ' ▁ ' ) ; NEW_LINE S1 . clear ( ) ; NEW_LINE S2 . clear ( ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 7 , 7 , 3 , 2 , 3 ] ; NEW_LINE N = len ( arr ) ; NEW_LINE findDifferenceArray ( arr , N ) ; NEW_LINE DEDENT