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.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannerscan=newScanner(System.in);intN=scan.nextInt();List<Integer>list=newArrayList<Integer>(N);for(inti=0;i<N;i++){list.add(scan.nextInt());}intQ=scan.nextInt();for(inti=1;i<=Q;i++){Stringquery=scan.next();if(query.toLowerCase().equals("insert")){intindex=scan.nextInt();intelement=scan.nextInt();list.add(index,element);}elseif(query.toLowerCase().equals("delete")){intindexToDelete=scan.nextInt();list.remove(indexToDelete);}elseSystem.out.println("Not valid input");}scan.close();list.stream().forEach(item->System.out.print(item+" "));}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java List
You are viewing a single comment's thread. Return to all comments →