If the jth group is the segment from it . . i , we change all the elements in this range to this range 's most occurring element
for it in range ( i , j - 2 , - 1 ) : NEW_LINE freq [ ar [ it ] ] = freq . get ( ar [ it ] , 0 ) + 1 NEW_LINE INDENT newElementFreq = freq [ ar [ it ] ] NEW_LINE if ( newElementFreq > freqOfMode ) : NEW_LINE INDENT freqOfMode = newElementFreq NEW_LINE DEDENT DEDENT