We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main (String[] args){
try(Scanner sc = new Scanner(System.in)){
//it is n lines
int n = sc.nextInt();//
ArrayList<ArrayList<Integer>> arr = new ArrayList<>();
for(int i=0; i <n; i++){
int d = sc.nextInt();
ArrayList<Integer> midArr = new ArrayList<>();
for(int j =0; j<d;j++){
midArr.add(sc.nextInt());
}
arr.add(midArr);
}
//q queries
int q = sc.nextInt();
ArrayList<ArrayList<Integer>> que = new ArrayList<>();
for(int i=0; i <q; i++){
ArrayList<Integer> midQue = new ArrayList<>();
for(int j =0; j<2;j++){
midQue.add(sc.nextInt());
}
que.add(midQue);
}
//get x,y and check the existence
for(int i=0; i <q; i++){
int x = que.get(i).get(0) -1;
int y = que.get(i).get(1)-1;
if (x >= 0 && x < arr.size() && y >= 0 && y < arr.get(x).size()) {
System.out.println( arr.get(x).get(y));
} else {
System.out.println("ERROR!");
}
}
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Arraylist
You are viewing a single comment's thread. Return to all comments →
import java.util.*;
public class HR082502 {
}