You are viewing a single comment's thread. Return to all comments →
May I know what is the issue with my code? It passed Test Case 3 but failed the rest of the Test Cases.
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); String[] s = sc.nextLine().split(" "); List<Integer> L = new ArrayList<>(); for (String num : s) { L.add(Integer.parseInt(num)); } int q = sc.nextInt(); sc.nextLine(); while (q > 0) { String operation = sc.nextLine(); if (operation.equalsIgnoreCase("Insert")) { String[] xy = sc.nextLine().split(" "); L.add(Integer.parseInt(xy[0]), Integer.parseInt(xy[1])); } else { int index = sc.nextInt(); L.remove(index); } q--; } for (Integer num : L) { System.out.printf("%d ", num); } }
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 →
May I know what is the issue with my code? It passed Test Case 3 but failed the rest of the Test Cases.