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.
import java.io.;
import java.util.;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
// you need to answer a few queries
Scanner sc = new Scanner(System.in);
ArrayList[] al = new ArrayList[20000]; // including 2000 elements
int lists = sc.nextInt();
// read numbers;
for (int i = 0; i < lists; i++) {
al[i] = new ArrayList(); //
int number = sc.nextInt();
for(int j = 0; j < number; j++) {
int value = sc.nextInt();
al[i].add(value);
}
}
// testing the queries;
int queries = sc.nextInt();
for (int i = 0; i < queries; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
try {
System.out.println(al[x-1].get(y-1));
} catch (Exception e) {
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
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 →
import java.io.; import java.util.; import java.util.Scanner; public class Solution {
}