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<Integer>[] arr = new ArrayList[n];
for (int i = 0; i < n; i++) {
int m = sc.nextInt();
arr[i] = new ArrayList<>();
for (int j = 0; j < m; j++) {
int value = sc.nextInt();
arr[i].add(value);
}
}
int mn = sc.nextInt();
for (int i = 0; i < mn; i++) {
int val1 = sc.nextInt()-1;
int val2 = sc.nextInt()-1;
if (val1 < 0 || val1 >= n || val2 < 0 || val2 >= arr[val1].size()) {
System.out.println("ERROR!");
} else {
System.out.println(arr[val1].get(val2));
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Java Arraylist
You are viewing a single comment's thread. Return to all comments →