Print all the sum pairs which occur maximum number of times | C # implementation of above approach ; Function to find the sum pairs that occur the most ; Hash - table ; Keep a count of sum pairs ; Variables to store maximum occurrence ; Iterate in the hash table ; Print all sum pair which occur maximum number of times ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void findSumPairs ( int [ ] a , int n ) { Dictionary < int , int > mpp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( mpp . ContainsKey ( a [ i ] + a [ j ] ) ) { var val = mpp [ a [ i ] + a [ j ] ] ; mpp . Remove ( a [ i ] + a [ j ] ) ; mpp . Add ( a [ i ] + a [ j ] , val + 1 ) ; } else { mpp . Add ( a [ i ] + a [ j ] , 1 ) ; } } } int occur = 0 ; foreach ( KeyValuePair < int , int > entry in mpp ) { if ( entry . Value > occur ) { occur = entry . Value ; } } foreach ( KeyValuePair < int , int > entry in mpp ) { if ( entry . Value == occur ) Console . WriteLine ( entry . Key ) ; } } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 8 , 3 , 11 , 4 , 9 , 2 , 7 } ; int n = a . Length ; findSumPairs ( a , n ) ; } }