HackerRank Java- List
Given a list, L, of N integers, perform Q queries on the list. Once all queries are completed, print the modified list as a single line of space-separated integers.
- import java.io.*;
- import java.util.*;
- import java.text.*;
- import java.math.*;
- import java.util.regex.*;
-
- public class Solution {
-
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- LinkedList<Integer> list = new LinkedList<>();
- int n = sc.nextInt();
- for (int i = 0; i < n; i++) {
- list.add(sc.nextInt());
- }
- n = sc.nextInt();
- for (int i = 0; i < n; i++) {
- if (sc.next().equals("Insert"))
- list.add(sc.nextInt(), sc.nextInt());
- else
- list.remove(sc.nextInt());
- }
- sc.close();
-
- for (Integer i : list) {
- System.out.print(i + " ");
- }
- }
- }