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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Java
  3. Data Structures
  4. Java Arraylist
  5. Discussions

Java Arraylist

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • bhuvaneswarand15
    2 months ago+ 0 comments

    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. */
        List<List<Integer>> listOfArray = new ArrayList<>();
        Scanner s= new Scanner(System.in);
        int n =s.nextInt();
        for(int i=0;i<n;i++){
            int d=s.nextInt();
            List<Integer> listf = new ArrayList<Integer>() ;
            for(int j=0;j<d;j++){
            listf.add(s.nextInt());
            }
            listOfArray.add(listf);
        }
       // System.out.println(listOfArray);
       int q =s.nextInt();
       for(int i=0;i<q;i++){
         int x= s.nextInt();
         int y =s.nextInt();
         try{
        System.out.println( listOfArray.get(x-1).get(y-1));
         }
         catch(Exception ex){
             System.out.println("ERROR!");
         }
       }
            s.close();
    
    
    }
    

    }

    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy