X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Print alternate elements of an array
School Accuracy: 50.02% Submissions: 82469 Points: 0

You are given an array A of size N. You need to print elements of A in alternate order (starting from index 0).

Example 1:

Input:
N = 4
A[] = {1, 2, 3, 4}
Output:
1 3

Example 2:

Input:
N = 5
A[] = {1, 2, 3, 4, 5}
Output:
1 3 5

Your Task:
Since this is a function problem, you just need to complete the provided function void print(int ar[],int n)

Constraints:
1 <= N <= 105
1 <= Ai <= 105

Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Print alternate elements of an array

Output Window