below is my code -->
public static int ImpofTime(Queue q,int[] orig_order, int n) throws Exception{
// Write your Code here
int answer = 0;
for(int i = 0; i < n; i++) {
if(q.getFront() == orig_order[i]) {
answer++;
q.dequeue();
} else {
while(q.getFront() != orig_order[i]) {
int var = q.getFront();
q.enqueue(var);
q.dequeue();
answer++;
}
answer++;
q.dequeue();
}
}
return answer;
}
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) throws Exception {
Queue q = new Queue();
int n = scn.nextInt();
int[] process = new int[n];
for (int i = 0; i < n; i++) {
q.enqueue(scn.nextInt());
}
for(int i = 0;i < n;i++){
process[i] = scn.nextInt();
}
System.out.print(ImpofTime(q,process,n));
}