326 2/22/2016 9:48:51 AM


:

Assumption- Its non sorted Array A[9,2,1,7,2,7,4,7,9,...N]

:

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

:

A[9,2,1,7,2,7,4,7,9,...N]

DICTIONARY <KEY, VALUE> DUPS;

FOR I = 0 TO A[N-1]

CURRENT_DUP_COUNT=0;

IF A[I] NOT IN DUPS[]

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

END IF

NEXT I

RETURN DUPS;