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); // making object of scanner class
int N=sc.nextInt(); // getting the size of array list
ArrayList<Integer> l=new ArrayList(); // intialising the array list
int getnum;
// used loop for getting input and adding it to array list
for(int i=0;i<N;i++)
{
getnum=sc.nextInt(); // taking input
l.add(getnum); // adding element into the array list
}
int Q=sc.nextInt(); // taking the total number of queries
for(int i=0;i<Q;i++)
{
String query=sc.next(); // taking query as input and check for further operation
if(query.equals("Insert"))
{
int index=sc.nextInt();
int num=sc.nextInt();
l.add(index,num);
}
if(query.equals("Delete"))
{
int index=sc.nextInt();
l.remove(index);
}
}
for(int i=0;i<l.size();i++)
{
System.out.print(l.get(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 →
// here is the detailed and easiest solution
import java.io.; import java.util.;
public class Solution {
}