ExpediaOA #1
Minimum Steps to Reorder Neural Network Layers
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyTwo Pointers
In each step, you may only take the layer at the end of the current list and insert it at any position. desired is guaranteed to be reachable.
Input
The first line contains n (1≤n≤200000), the second line current, and the third line desired. Both arrays are permutations of 1..n.
Output
Output the minimum number of operations.
Example 1
Input:
5
2 1 3 5 4
2 4 1 5 3
Output:
2
Example 2
Input:
3
1 2 3
1 2 3
Output:
0
Example 3
Input:
3
3 2 1
1 2 3
Output:
2
Editorial
Loading solution…