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 →

  • Emre_Karakaya
    2 months ago+ 1 comment
            Scanner in =new Scanner(System.in);
            int n=in.nextInt();
            ArrayList<ArrayList<Integer>> l = new ArrayList<>();
    
            for(int i=0;i<n;i++){
                ArrayList<Integer> temp = new ArrayList<>();
                int d=in.nextInt();
                for(int x=0;x<d;x++){
                    temp.add(in.nextInt());
                }
                l.add(temp);  
            }
            
            int q=in.nextInt();
            for(int i =0;i<q;i++){
                int a=in.nextInt();
                int b=in.nextInt();
                try{
                     System.out.println(l.get(a-1).get(b-1));
                }catch(Exception e){
                     System.out.println("ERROR!");
                }
       
            }
            in.close();
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy