Competitive Programming Solutions

GitHub
back to dashboard

F. Front - End

Codeforces - Contest #3.1 · limit: 1s · memory: 256MB · view on codeforces

input

5
1 2 3 4 5

output

1 5 2 4 3
Main.java
static void solve() {

        // Write your solution here
        int n = in.nextInt();
        Deque<Integer> nums = new ArrayDeque<>();
        for(int i = 0; i < n; i++){
            nums.addLast(in.nextInt());
        }
        while(!nums.isEmpty()){
            out.print(nums.pollFirst() + " ");
            if(!nums.isEmpty())
            out.print(nums.pollLast() + " ");
        }
    }