Count pairs of indices having sum of indices same as the sum of elements at those indices | Function to find all possible pairs of the given array such that the sum of arr [ i ] + arr [ j ] is i + j ; Stores the total count of pairs ; Iterate over the range ; Iterate over the range ; Print the total count ; Driver Code
function countPairs ( arr , N ) { let answer = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( arr [ i ] + arr [ j ] == i + j ) { answer ++ ; } } } document . write ( answer ) ; } let arr = [ 0 , 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; countPairs ( arr , N ) ;