Print all the sum pairs which occur maximum number of times | 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
function findSumPairs ( a , n ) { let mpp = new Map ( ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( mpp [ a [ i ] + a [ j ] ] ) mpp [ a [ i ] + a [ j ] ] ++ ; else mpp [ a [ i ] + a [ j ] ] = 1 ; } } let occur = 0 ; for ( var it in mpp ) { if ( mpp [ it ] > occur ) { occur = mpp [ it ] ; } } for ( var it in mpp ) { if ( mpp [ it ] == occur ) document . write ( it , ' ' ) ; } } let a = [ 1 , 8 , 3 , 11 , 4 , 9 , 2 , 7 ] ; let len = a . length ; findSumPairs ( a , len ) ;