Check if a pair of integers A and B can coincide by shifting them by distances arr [ ( A % N + N ) % N ] and arr [ ( B % N + N ) % N ] | Function to check if two integers coincide at a point ; Store the final position of integers A and B ; Iterate over the range [ 0 , n ] ; Store the final position of the integer i ; If temp is present in the Map ; Print Yes and return ; Mark its final position as visited ; If every integer stored in the Map is unique ; Driver Code
function checkSamePosition ( arr , n ) { var mp = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { var temp = ( ( i + arr [ i ] ) % n + n ) % n ; if ( mp . has ( temp ) ) { document . write ( " " ) ; return ; } if ( mp . has ( temp ) ) { mp . set ( temp , mp . get ( temp ) + 1 ) } else mp . set ( temp , 1 ) } document . write ( " " ) ; } var arr = [ 5 , 4 , 3 ] ; var N = arr . length ; checkSamePosition ( arr , N ) ;