Print Alternate Elements

Practice this coding question on Coding Gurukul.

Problem statement

A monitoring dashboard reduces clutter by displaying every other reading from a saved log. It always begins with the first reading and keeps the original order. Your task Print the elements at zero-based indices 0, 2, 4, and so on. Important details The selection depends on position, not on whether a value is even or odd. Do not reorder the array or remove duplicates. When the number of readings is odd, the final reading is included. A one-element log prints that element. The output contains exactly ceil(n/2) values. Worked example For readings 9, 8, 7, 6, 5, select positions 0, 2, and 4. The output is 9 7 5.

Input format

The first line contains n. The second line contains n integers.

Output format

Print the selected elements separated by spaces.

Constraints

1 <= n <= 100000; -1000000000 <= a[i] <= 1000000000.

Sample input

5
9 8 7 6 5

Sample output

9 7 5

Sign in to run or submit a solution in C++, Java or Python.

Loading Coding Gurukul…