Maximum occurred integers after M circular operations in given range | C # program for the above approach ; 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
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void mostvisitedsector ( int N , ArrayList A ) { int maxVisited = 0 ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < A . Count - 1 ; i ++ ) { int start = ( int ) A [ i ] % N ; int end = ( int ) A [ i + 1 ] % N ; while ( start != end ) { if ( start == 0 ) { if ( mp . ContainsKey ( N ) ) mp [ N ] = mp [ N ] + 1 ; else mp [ N ] = 1 ; if ( mp [ N ] > maxVisited ) { maxVisited = mp [ N ] ; } } else { if ( mp . ContainsKey ( start ) ) mp [ start ] = mp [ start ] + 1 ; else mp [ start ] = 1 ; if ( mp [ start ] > maxVisited ) { maxVisited = mp [ start ] ; } } start = ( start + 1 ) % N ; } } int last_element = ( int ) A [ A . Count - 1 ] ; if ( mp . ContainsKey ( last_element ) ) mp [ last_element ] = mp [ last_element ] + 1 ; else mp [ last_element ] = 1 ; if ( mp [ last_element ] > maxVisited ) { maxVisited = mp [ last_element ] ; } foreach ( var x in mp ) { if ( ( int ) x . Value == maxVisited ) { Console . Write ( x . Key + " ▁ " ) ; } } } public static void Main ( ) { int N = 4 ; ArrayList arr = new ArrayList ( ) { 1 , 2 , 1 , 2 } ; mostvisitedsector ( N , arr ) ; } }