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.



  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6. public class Solution {
  7. public static void main(String[] args) {
  8. Scanner sc = new Scanner(System.in);
  9. LinkedList<Integer> list = new LinkedList<>();
  10. int n = sc.nextInt();
  11. for (int i = 0; i < n; i++) {
  12. list.add(sc.nextInt());
  13. }
  14. n = sc.nextInt();
  15. for (int i = 0; i < n; i++) {
  16. if (sc.next().equals("Insert"))
  17. list.add(sc.nextInt(), sc.nextInt());
  18. else
  19. list.remove(sc.nextInt());
  20. }
  21. sc.close();
  22. for (Integer i : list) {
  23. System.out.print(i + " ");
  24. }
  25. }
  26. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube