I am trying to find the subsequence of two arrays A
and B
. My code is as follows:
import java.io.*;
import java.util.*;
public class TestClass {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter wr = new PrintWriter(System.out);
int T = Integer.parseInt(br.readLine().trim());
for(int t_i = 0; t_i < T; t_i++)
{
String[] line = br.readLine().split(" ");
int N = Integer.parseInt(line[0]);
int M = Integer.parseInt(line[1]);
int X = Integer.parseInt(line[2]);
String[] arr_A = br.readLine().split(" ");
int[] A = new int[N];
for(int i_A = 0; i_A < arr_A.length; i_A++)
{
A[i_A] = Integer.parseInt(arr_A[i_A]);
}
String[] arr_B = br.readLine().split(" ");
int[] B = new int[M];
for(int i_B = 0; i_B < arr_B.length; i_B++)
{
B[i_B] = Integer.parseInt(arr_B[i_B]);
}
String out_ = solve(N, M, X, A, B);
System.out.println(out_);
}
wr.close();
br.close();
}
static String solve(int N, int M, int X, int[] A, int[] B){
int k=0;
Arraylist<Arraylist<Integer>> arr=new Arraylist<>(); //subsequence of array A
Arraylist<Arraylist<Integer>> arr_1=new Arraylist<>(); // subsequence of array B
Arraylist<Integer> temp=new Arraylist<>();
int count=0;
arr.add(A);
//subsequence of array A
while(k!=arr.size()){
if(arr.get(k).size!=1){
for(int i=0;i<arr.get(k).size();i++){
for(int j=0;j<arr.get(k).size();j++){
if(i!=j){
temp.add(arr.get(k).get(j));
}
}
if(!arr.contains(temp))
arr.add(temp);
temp.clear();
}
++k;
}
else
break;
}
arr_1.add(B);
k=0;
//subsequence of array B
while(k!=arr_1.size()){
if(arr_1.get(k).size!=1){
for(int i=0;i<arr_1.get(k).size();i++){
for(int j=0;j<arr_1.get(k).size();j++){
if(i!=j){
temp.add(arr_1.get(k).get(j));
}
}
if(!arr_1.contains(temp))
arr_1.add(temp);
temp.clear();
}
++k;
}
else
break;
}
for(int i=0; i<arr.size(); i++){
if(arr.get(k).size()==arr_1.get(k).size()){
for(int j=0; j<arr_1.size()-1; j++){
if((arr.get(i).get(j)<arr_1.get(i).get(j)) && arr_1.get(i).get(j)<arr.get(i).get(j+1))
++count;
}
if (count==X){
temp.addAll(arr.get(i));
temp.addAll(arr_1.get(i));
break;
}
else
count=0;
}
}
if(temp.size()==X)
return "YES";
else
return "NO";
}
}
Now, when I run the code, I am greeted with the error Cannot find symbol Arraylist...
, all over the code. I have also included the import
statement, but it didn't solve anything. What am I doing wrong here?