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) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
ArrayList> list = new ArrayList<>();
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int m = sc.nextInt();
ArrayList<Integer> a = new ArrayList<Integer>();
for (int j = 0; j < m; j++) {
a.add(sc.nextInt());
}
list.add(a);
}
int x = sc.nextInt();
for (int i = 0; i < x; i++) {
int num1 = sc.nextInt()-1;
int num2 = sc.nextInt()-1;
if(num1<list.size() && num1>=0) {
if(num2<list.get(num1).size() && num2>=0) {
System.out.println(list.get(num1).get(num2));
}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
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Java Arraylist
You are viewing a single comment's thread. Return to all comments →
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner sc = new Scanner(System.in); ArrayList> list = new ArrayList<>(); int n = sc.nextInt();