Photoshoot 2
InterviewTime limit2sMemory limit1024 MB
Given a start permutation and a target permutation, count the fewest cows you must move left (one at a time) to reach the target order.
- Level
Medium5 of 10
- Topics
- Array, Greedy, Hash map, Two pointers
- Solved
- No attempts yet
Problem
In what seems to be a familiar occurrence, Farmer John is lining up his cows (), conveniently numbered , for a photograph.
Initially, the cows are lined up in the order from left to right. Farmer John's goal is to line up the cows in the order from left to right. To accomplish this, he may perform a series of modifications to the ordering. Each modification consists of choosing a single cow and moving it some number of positions to the left.
Please count the minimum number of modifications required in order for Farmer John to line up his cows in the desired order.
Input
The first line of input contains . The second line contains . The third line contains .
Output
Print the minimum number of modifications required to produce Farmer John's desired ordering.