map and freqOfMode are together used to keep track of the frequency of the most occurring element in [ 0. . i ]
unordered_map < int , int > freq ; int freqOfMode = 0 ; for ( int it = 0 ; it <= i ; it ++ ) { freq [ ar [ it ] ] ++ ; int newElementFreq = freq [ ar [ it ] ] ; if ( newElementFreq > freqOfMode ) freqOfMode = newElementFreq ; }