Shuffle puff CSTR00

Problem link:
Practice
Contest link

Author: Vanshita tiwari.
Tester: Ujjawal Gupta
Editorial:Ujjawal Gupta

Difficulty:
Easy.

Prerequisite:
Array.

Explanation & Algotithm:
In this problem, You have to make array of size 2*n & then make two variables, 1st one points to the 0th element & 2nd one points to nth element. iterate both variable & in each iteration print the element that is present in both the indexes.

Solution:

Setter's Code

import java.util.;
import java.lang.
;
import java.io.*;

class Solution_1 {

public static void main (String args[])  {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();

	int nums[] = new int[2*n];
	for(int i=0; i<2*n; i++) {
		nums[i] = sc.nextInt();
	}	

	 int a = 1;
             int b = n;	
	int []res = new int[2*n];
            int i=1;
            res[0] = nums[0];
	        res[2*n-1] = nums[2*n-1];
 	        while(a < n && b < 2*n-1) {
  	           res[i++] = nums[b];
   	           res[i++] = nums[a];
               a++;
               b++;
         }
  for(int idx=0; idx<2*n; idx++){
	System.out.print(res[idx] + " ");
  }
 }

}