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.
Most of you used your high level knowledge to make it work, but here it is for begineers like me who would like to solve it with an easy method:
import java.io.;
import java.util.;
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. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arrObj;
// data list
ArrayList<ArrayList<Integer>> dataList = new ArrayList<>();
// making array list to store data
for (int i = 0; i < n; i++){
int nArray = sc.nextInt();
ArrayList<Integer> arr = new ArrayList<>();
for(int j = 0; j < nArray; j++){
arrObj = sc.nextInt();
arr.add(arrObj);
}
// System.out.println(arr);
dataList.add(arr);
}
int n2 = sc.nextInt();
//query list
// ArrayList<ArrayList<Integer>> queryList = new ArrayList<>();
// making data list to fetch data or else print Erorr
for (int i = 0; i < n2; i++){
int row = sc.nextInt();
int coloumn = sc.nextInt();
// System.out.println(arr2);
try{
System.out.println(dataList.get(row-1).get(coloumn-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
Java Arraylist
You are viewing a single comment's thread. Return to all comments →
Most of you used your high level knowledge to make it work, but here it is for begineers like me who would like to solve it with an easy method:
import java.io.; import java.util.;
public class Solution {
}
`