Convert an array into another by repeatedly removing the last element and placing it at any arbitrary index | Function to count the minimum number of operations required to convert the array A [ ] into array B [ ] ; Stores the index in the first permutation A [ ] which is same as the subsequence in B [ ] ; Find the first i elements in A [ ] which is a subsequence in B [ ] ; If element A [ i ] is same as B [ j ] ; Return the count of operations required ; Driver Code
function minCount ( A , B , N ) { var i = 0 for ( let j = 0 ; j < N ; j ++ ) { if ( A [ i ] == B [ j ] ) i += 1 } return N - i } var A = [ 1 , 2 , 3 , 4 , 5 ] var B = [ 1 , 5 , 2 , 3 , 4 ] N = A . length document . write ( minCount ( A , B , N ) )