338 2/22/2016 9:41:27 AM


:

Assumption- Its Sorted Array A[1,2,2,3,4,4,4,...N]

:

Return dictionary of duplicate with duplicate count e.g. {[2,2],[4,3],...}

:

DICTIONARY <KEY, VALUE> DUPS;

FOR I = 0 TO A[N-1]

CURRENT_DUP_COUNT=0;

FOR J=I to A[N-1]

IF A[I]=A[J]

CURRENT_DUP_COUNT=CURRENT_DUP_COUNT+1;

DUPS[KEY=A[I]].VALUE=CURRENT_DUP_COUNT;

END IF

NEXT J

NEXT I

RETURN DUPS;