-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue3.java
More file actions
41 lines (41 loc) · 758 Bytes
/
Queue3.java
File metadata and controls
41 lines (41 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.*;
import java.util.LinkedList;
class Queue3
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
Queue<Integer> q=new LinkedList<>();
for(int i=0;i<n;i++)
{
int x=in.nextInt();
if(x<0||x>1)
return;
q.add(x);
}
int s[]=new int[n];
for(int i=0;i<n;i++)
{
s[i]=in.nextInt();
if(s[i]<0||s[i]>1)
return;
}
int i=0,tri=0;
while(!q.isEmpty() && tri<q.size())
{
if(q.peek()==s[i])
{
q.poll();
i++;
tri=0;
}
else
{
q.add(q.poll());
tri++;
}
}
System.out.println(q.size());
}
}