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) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<ArrayList<Integer>> list = new ArrayList<>();
for(int i=1;i<=n;i++){
ArrayList<Integer> newList = new ArrayList<>();
int d = sc.nextInt();
for(int j=1;j<=d;j++){
int l = sc.nextInt();
newList.add(l);
}
list.add(newList);
}
int q = sc.nextInt();
for(int i=0;i<q;i++){
int x = sc.nextInt()-1;
int y = sc.nextInt()-1;
if(list.get(x).size()>y){
System.out.println(list.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 →
Solution:
public class Solution {
}