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.
importjava.io.*;importjava.util.*;importjava.text.*;importjava.math.*;importjava.util.regex.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannersc=newScanner(System.in);intnoOfArrays=sc.nextInt();/* Saving numbers in 2D ArrayList */ArrayList<ArrayList<Integer>>lists=newArrayList<>();for(inti=0;i<noOfArrays;i++){intnewArrayLength=sc.nextInt();ArrayList<Integer>list=newArrayList<>();for(intj=0;j<newArrayLength;j++){list.add(sc.nextInt());}lists.add(list);}/* Finding position of the number for each queries */intnoOfQueries=sc.nextInt();while(noOfQueries>0){introw=sc.nextInt();intcolumn=sc.nextInt();try{System.out.println(lists.get(row-1).get(column-1));}catch(IndexOutOfBoundsExceptione){System.out.println("ERROR!");}noOfQueries--;}}}
pls follow for better code and message for any kind of coding language problems
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 →
pls follow for better code and message for any kind of coding language problems