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.
Hi All, I have a question. the code below passes almost all the tests except two, in which the number of given elements (n) is 20000. I suppose the code generates runtime error due to large number of elements, I just don't understand why.
import java.io.;
import java.util.;
public class Solution {
public static void main(String[] args) {
int n,d;
List<List<Integer>> arr = new ArrayList<List<Integer>>();
Scanner key = new Scanner(System.in);
n = key.nextInt();
for (int i=0;i<n;i++) {
d = key.nextInt();
for (int j=0;j<d;j++) {
List<Integer> arr2 = new ArrayList<Integer>();
arr.add(arr2);
arr.get(i).add(key.nextInt());
}
}
n = key.nextInt();
for (int i=0;i<n;i++) {
int x = key.nextInt()-1;
int y = key.nextInt()-1;
try {
System.out.println(arr.get(x).get(y));
}
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
Java Arraylist
You are viewing a single comment's thread. Return to all comments →
Hi All, I have a question. the code below passes almost all the tests except two, in which the number of given elements (n) is 20000. I suppose the code generates runtime error due to large number of elements, I just don't understand why.
import java.io.; import java.util.;
public class Solution {
}