forked from NinjaHacker7/Cynosure-Information
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathst3.java
More file actions
54 lines (46 loc) · 1.33 KB
/
Copy pathst3.java
File metadata and controls
54 lines (46 loc) · 1.33 KB
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
42
43
44
45
46
47
48
49
50
51
52
import java.util.*;
class st3
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int arr1[] = new int[n];
for(int i=0;i<n;i++){
arr1[i] = scn.nextInt();
}
int m = scn.nextInt();
int arr2[] = new int[m];
for(int i=0;i<m;i++){
arr2[i] = scn.nextInt();
}
Stack<Integer> st = new Stack<>();
String ans = "";
int idx = 0;
HashSet<Integer> set = new HashSet<>();
for(int v2 : arr2){
System.out.println("Processing:"+v2);
if(set.contains(v2)){
while(st.size() != 0 && st.peek() != v2){
ans += "B";
st.pop();
}
ans += "B";
st.pop();
}else{
while(st.size() == 0 || st.peek() != v2){
st.push(arr1[idx]);
set.add(arr1[idx]);
ans+="A";
idx++;
}
if(st.peek() == v2){
ans += "B";
st.pop();
}
}
}
System.out.println(ans);
}
}