Remove Even-Indexed Elements

Easy
0/40
1 upvote
Asked in company
Infogain

Problem statement

You are given an array of integers, arr. Your task is to process this array and remove all elements that are located at an even index. The remaining elements (those originally at odd indices) should be collected into a new list, preserving their relative order.


Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first line contains a single integer N, the size of the array.

The second line contains N space-separated integers, representing the elements of the array.


Output Format:
Print a single line containing the elements that were at odd indices, separated by spaces.

If no elements remain after the removal (e.g., if the input array has only one element), print an empty line.


Note:
Array indices are considered 0-based. Therefore, "even places" or "even indices" refer to indices 0, 2, 4, and so on.
Sample Input 1:
6
1 2 3 4 5 6


Sample Output 1:
2 4 6


Explanation for Sample 1:
The array elements are at indices 0 through 5.
  Elements at even indices (0, 2, 4) are 1, 3, and 5. These are removed.
  Elements at odd indices (1, 3, 5) are 2, 4, and 6. These are kept.


Sample Input 2:
5
10 20 30 40 50


Sample Output 2:
20 40


Explanation for Sample 2:
Elements at even indices (0, 2, 4) are 10, 30, and 50. These are removed.
Elements at odd indices (1, 3) are 20 and 40. These are kept.


Expected Time Complexity:
The expected time complexity is O(N).


Constraints:
1 <= N <= 10^5
-10^9 <= arr[i] <= 10^9

Time limit: 1 sec
Approaches (1)
Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
Remove Even-Indexed Elements
Full screen
Console