Morty and his two sequences
All submissions for this problem are available.Morty has two sequences of length $N$, each containing same non-repeating integers. He dares you to convert the first sequence into second. In one move you can either remove the first or the last element from the first sequence and insert it in any position of your choice in the same squence itself. Morty wants to know the minimum number of such moves ( possibly zero ) to convert the first sequence into second. ###Input: - First line will contain $N$,denoting the length of the sequences. - Second line contains $N$ integers, $a_1,a_2,a_3...a_n$ denoting the first sequence. - Third line contains $N$ integers, $b_1,b_2,b_3...b_n$ denoting the second sequence. ###Output: Output a single integer $i.e$ the minimum number of moves to convert the first sequence into second. ###Constraints - $1 \leq N \leq 2*10^5$ - $1 \leq a[i], b[i] \leq 10^9$ ###Sample Input: 4 4 2 3 1 1 2 3 4 ###Sample Output: 2 ###EXPLANATION: First move: remove number 1 from end and place it in the second position resulting in $[ 4 ,1, 2, 3 ]$ Second move: remove number 4 from the beginning and place it in the end resulting in $[ 1 ,2 ,3 ,4 ]$
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.