Closest Numbers

  • + 0 comments

    Yup. Sample Test #2 when you "Run", Test #5 when you submit. It should be corrected but here is an easy Java workaround:

        int n = scanner.nextInt();
    
        int[] arr = new int[n];
    
        int i = 0; 
        try{
            for (; i < n; i++) {
                arr[i] = scanner.nextInt();
            }
        } catch(NoSuchElementException ex){
            arr = Arrays.copyOf(arr, i);
        }