Absolute distinct count in a sorted array | This function returns number of distinct absolute values among the elements of the array ; set keeps all unique elements ; Driver Code
def distinctCount ( arr , n ) : NEW_LINE INDENT s = set ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT s . add ( abs ( arr [ i ] ) ) NEW_LINE DEDENT return len ( s ) NEW_LINE DEDENT arr = [ - 2 , - 1 , 0 , 1 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Count ▁ of ▁ absolute ▁ distinct ▁ values : " , distinctCount ( arr , n ) ) NEW_LINE