Maximum occurred integers after M circular operations in given range | Function to find the maximum occurred integer after completing all circular operations ; Stores the highest visit count for any element ; Stors the number of times an element is visited ; Iterate over the array ; Iterate over the range circularly form start to end ; Count number of times an element is visited ; Increment frequency of N ; Update maxVisited ; Increment frequency of start ; Update maxVisited ; Increment the start ; Increment the count for the last visited element ; Print most visited elements ; Driver Code ; Function Call
def mostvisitedsector ( N , A ) : NEW_LINE INDENT maxVisited = 0 NEW_LINE mp = { } NEW_LINE for i in range ( 0 , len ( A ) - 1 ) : NEW_LINE INDENT start = A [ i ] % N NEW_LINE end = A [ i + 1 ] % N NEW_LINE while ( start != end ) : NEW_LINE INDENT if ( start == 0 ) : NEW_LINE INDENT if N in mp : NEW_LINE INDENT mp [ N ] = mp [ N ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ N ] = 1 NEW_LINE DEDENT if ( mp [ N ] > maxVisited ) : NEW_LINE INDENT maxVisited = mp [ N ] NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if start in mp : NEW_LINE INDENT mp [ start ] = mp [ start ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ start ] = 1 NEW_LINE DEDENT if ( mp [ start ] > maxVisited ) : NEW_LINE INDENT maxVisited = mp [ start ] NEW_LINE DEDENT DEDENT start = ( start + 1 ) % N NEW_LINE DEDENT DEDENT if A [ - 1 ] in mp : NEW_LINE INDENT mp [ A [ - 1 ] ] = mp [ A [ - 1 ] ] + 1 NEW_LINE DEDENT if ( mp [ A [ - 1 ] ] > maxVisited ) : NEW_LINE INDENT maxVisited = mp [ A [ - 1 ] ] NEW_LINE DEDENT for x in mp : NEW_LINE INDENT if ( mp [ x ] == maxVisited ) : NEW_LINE INDENT print ( x , end = ' ▁ ' ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 4 NEW_LINE arr = [ 1 , 2 , 1 , 2 ] NEW_LINE mostvisitedsector ( N , arr ) NEW_LINE DEDENT