text: Maximize count of corresponding same elements in given Arrays by Rotation | Function that prlets maximum equal elements ; Vector to store the index of elements of array b ; Storing the positions of array B ; frequency array to keep count of elements with similar difference in distances ; Iterate through all element in arr1 [ ] ; Calculate number of shift required to make current element equal ; If d is less than 0 ; Store the frequency of current diff ; Compute the maximum frequency stored ; Printing the maximum number of equal elements ; Given two arrays ; Function Call
code: function maximumEqual ( a , b , n ) { let store = Array . from ( { length : 1e5 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { store [ b [ i ] ] = i + 1 ; } let ans = Array . from ( { length : 1e5 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { let d = Math . abs ( store [ a [ i ] ] - ( i + 1 ) ) ; if ( store [ a [ i ] ] < i + 1 ) { d = n - d ; } ans [ d ] ++ ; } let finalans = 0 ; for ( let i = 0 ; i < 1e5 ; i ++ ) finalans = Math . max ( finalans , ans [ i ] ) ; document . write ( finalans + " " ) ; } let A = [ 6 , 7 , 3 , 9 , 5 ] ; let B = [ 7 , 3 , 9 , 5 , 6 ] ; let size = A . length ; maximumEqual ( A , B , size ) ;