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) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0;i<n;i++){
int input = sc.nextInt();
arr.add(input);
}
int q = sc.nextInt();
for(int j=0;j<q;j++){
String Q = sc.next();
if(Q.equals("Insert")){
int x = sc.nextInt();
int y = sc.nextInt();
arr.add(x,y);
}else if(Q.equals("Delete")){
int x = sc.nextInt();
arr.remove(x);
}else{
System.out.println("Wrong Input");
}
}
for (Integer num : arr){
System.out.print(num+" ");
}
}
}
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 →
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
}