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.
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
List<Integer> list= new ArrayList<>(n);
for(int i=0;i<n;i++){
list.add(scan.nextInt());
}
int q=scan.nextInt();
for(int j=0;j<q;j++){
String str=scan.nextLine();
if(str.equalsIgnoreCase("Delete")){
int m=scan.nextInt();
list.remove(m);
}
if(str.equalsIgnoreCase("Insert")){
int x=scan.nextInt();
int y=scan.nextInt();
list.add(x, y);
}
}
list.forEach(i->{System.out.print(i+" ");});
}
}
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 →
Delete is not working
import java.io.; import java.util.;
public class Solution {
}