Given an array consisting of N distinct integers and another array consisting of M integers(not necessarily distinct) . You need to find out the minimum number of elements added to B so that A becomes the subsequence of B.
A subsequence is a sequence that can be derived by deleting some or no elements from the sequence without changing the order of remaining elements.
Input format
First line contains T (number of testcases)
for each test case
first line has N and M
second line contains N integers seperated by space
Third line contains M integers seperated by space
Output
Output the min no of elements to be added to array B so that the array A becomes the sub sequence of B
Constraints
1 < T <= 10
1 < N < 10^7
1 < M < 10^7
I tried this way.... but did not get accepted
I have found out the length of the longest common subsequence of array A and array B using Dynamic programming.
Then I returned*** min(0, len(A) - lengthofcommonsubsequenceofAandB)***
I is showing me the memory error..
So I again tried using 2 x N matrix but there my code was showing the time limit exceeded. where did I go wrong???
If any one has the solution or knows how to solve this please help me....