You are viewing a single comment's thread. Return to all comments →
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int size = sc.nextInt(); ArrayList<Integer> elements = new ArrayList<>(); for (int i = 0; i < size; i++) { elements.add(sc.nextInt()); } int numberQueries = sc.nextInt(); for (int j = 0; j < numberQueries; j++) { String query = sc.next(); if (query.equals("Insert")){ int position = sc.nextInt(); int replace = sc.nextInt(); elements.add(position, replace); } else{ elements.remove(sc.nextInt()); } } sc.close(); for (Integer integer : elements) { System.out.print(integer + " "); } } }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Java List
You are viewing a single comment's thread. Return to all comments →