You are viewing a single comment's thread. Return to all comments →
Hi Team, I have used this approach, let me know any updates
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); List<List<Integer>> mainList = new ArrayList<>(); for (int i = 0; i < n; i++) { int d = sc.nextInt(); List<Integer> subList = new ArrayList<>(); for (int j = 0; j < d; j++) { subList.add(sc.nextInt()); } mainList.add(subList); } List<List<Integer>> queryList = new ArrayList<>(); int q = sc.nextInt(); for (int k = 0; k < q; k++) { List<Integer> query = new ArrayList<>(); for (int l = 0; l < 2; l++) { query.add(sc.nextInt()); } queryList.add(query); } queryList.forEach(query -> { try { Integer record = mainList.get(query.get(0) - 1).get(query.get(1) - 1); System.out.println(record); } catch (Exception e) { System.out.println("ERROR!"); } }); } }
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 Team, I have used this approach, let me know any updates