hacker rank java 31 th (JAVA LIST)

31. JAVA LIST


import java.util.Scanner;
import java.util.LinkedList;

public class Solution {
    public static void main(String[] args) {
        /* Create and fill Linked List of Integers */
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        LinkedList<Integer> list = new LinkedList<>();
        for (int i = 0; i < N; i++) {
            int value = scan.nextInt();
            list.add(value);
        }
        
        /* Perfrom queries on Linked List */
        int Q = scan.nextInt();
        for (int i = 0; i < Q; i++) {
            String action = scan.next();
            if (action.equals("Insert")) {
                int index = scan.nextInt();
                int value = scan.nextInt();
                list.add(index, value);
            } else { // "Delete"
                int index = scan.nextInt();
                list.remove(index);//function  for remove operation for list
            }
        }
        scan.close();
        
        /* Print our updated Linked List */
        for (Integer num : list) {
            System.out.print(num + " ");
        }
    }
}


Compiler Message
Success
Input (stdin)Download
200
70114 42971 11429 85446 24387 41827 26690 70450 4751 50557 90543 11621 69356 96321 19603 93711 35620 22611 60955 95698 61882 52257 12351 7996 74129 68687 74707 53905 65918 29977 45604 6048 22429 69478 94024 31900 79584 67473 21059 83936 12711 78495 38663 21222 16468 841 16153 76827 70401 6485 66383 44625 57265 74475 83564 30955 13025 45441 94283 10142 41030 30023 30571 9453 99836 1797 94697 31515 24587 75659 29631 80954 69287 49501 45551 36531 74803 13199 78552 32516 62529 29627 35859 12944 22001 59034 16312 19577 39870 15981 88763 77724 83070 76031 53318 93462 115 30562 88786 78394 88955 69076 35344 7714 20786 14003 79153 70334 14330 35388 42266 15174 5684 75497 80994 34083 90185 29712 57504 29592 39331 53100 90829 20416 41354 29850 19238 52133 23703 56742 84574 10762 30120 15303 43406 26581 85117 32841 74228 18045 34350 90986 14810 77224 87732 99414 72035 34016 14148 62502 30593 76918 50784 56347 76338 87519 38119 59338 89070 2890 36301 86068 17631 25184 97714 83899 31035 35188 46282 71133 81570 8841 89{-truncated-}
Download to view the full testcase
Expected OutputDownload
70114 42971 85446 24387 90461 17759 41827 26690 70450 13835 50557 90543 11621 69356 1185 20073 19603 93711 35620 76049 22611 60955 95698 61882 52257 12351 7996 74129 74707 39892 53905 29977 5570 45604 6048 22429 94024 48733 31900 67473 21059 48051 86984 83936 12711 72211 17682 38663 21222 16468 89427 841 76827 47626 99597 6485 66383 44625 22197 13025 60018 30023 30571 9453 12003 99836 75455 30275 46635 1797 94697 24587 29631 80954 69287 45551 82735 66966 99991 13199 78552 62529 52149 29627 12944 91186 22001 59669 59034 15304 16312 50525 93216 19577 88763 77724 83070 65948 20524 76031 93462 17406 115 88786 82315 6381 97502 23050 78394 88955 69076 7714 20786 43248 14003 31243 79153 83435 14330 51360 42266 15174 5684 75497 80994 90185 33820 61540 53100 41354 29850 19238 56742 84574 49213 10762 43406 85117 36292 32841 74228 42810 34350 90986 77224 61755 53328 87732 94734 99414 72035 14148 62502 30593 19812 50784 56347 10405 94660 87519 96362 38119 89070 28595 36301 86068 17631 25184 12570 63951 97714 43153 31035 {-truncated-}
Download to view the full testcase



--Sundaram Dubey(CSE)

Comments

Popular posts from this blog

Amazon Web Services

Google Code-In mentorship experience :)

Hacker Rank all java and python problem solutions