Minimize operations to delete all elements of permutation A by removing a subsequence having order as array B | Function to find the minimum number of operations to delete all elements of permutation A in order described by B ; Stores the count of operations ; Stores the index of current integer in B to be deleted ; Loop to iterate over all values of B ; Stores the current index in A ; Iterate over all values A ; If current integer of B and A equal , increment the index of the current integer of B ; As the permutation A has been traversed completely , increment the count of operations by 1 ; Return Answer ; Driver Code
function minOperations ( A , B , N ) { let cnt = 0 ; let i = 0 ; while ( i < N ) { let j = 0 ; while ( j < N && i < N ) { if ( B [ i ] == A [ j ] ) { i ++ ; } j ++ ; } cnt ++ ; } return cnt ; } let A = [ 2 , 4 , 6 , 1 , 5 , 3 ] ; let B = [ 6 , 5 , 4 , 2 , 3 , 1 ] ; let N = A . length ; document . write ( minOperations ( A , B , N ) ) ;