• + 2 comments

    your time complexity : O(n + n) your space complexity : n

    you can optimize it a little bit with :

    time complexity : n + d space complexity : d

    public static void main(String[] args) { Scanner c = new Scanner(System.in); int n = c.nextInt(); int d = c.nextInt(); int skipPart[] = new int[d]; int j =0; for(int i = 0; i < n; i++) { if(i >= d) { System.out.print(c.nextInt() + " "); } else { skipPart[j] = c.nextInt(); j++; } } for(int i = 0; i < skipPart.length; i++) { System.out.print(skipPart[i] + " "); } }