CodingEasy
Check if numbers at even indices are even
Filed under Optum (UnitedHealth Group)
Free read 2 of 3Confirm that indexing starts at 0 and 'even number' means divisible by 2.
The question
Given an array of integers, determine whether every number located at an even index (0-indexed) is an even number.
Constraints
- 1 <= arr.length <= 10^5
- -10^9 <= arr[i] <= 10^9
- Indices are 0-based.
Examples
- Input
- [2, 5, 4, 3, 6]
- Output
- true
- Why
- Elements at even indices are arr[0]=2 (even), arr[2]=4 (even), and arr[4]=6 (even). All are even.
- Input
- [2, 5, 3, 3]
- Output
- false
- Why
- Element at index 2 is arr[2]=3, which is odd.
Approach
Confirm that indexing starts at 0 and 'even number' means divisible by 2.
Iterate through the entire array and check every element whose index % 2 == 0.
Loop through the array with a step of 2 (i += 2) and check each element using `arr[i] % 2 != 0` to return false early.
Single element array will always return true since index 0 is even.
Solution
O(N) time, O(1) space
def checkEvenIndicesAreEven(arr):
for i in range(0, len(arr), 2):
if arr[i] % 2 != 0:
return False
return True
Tips
- What they are testing: Test with empty arrays, single-element arrays, and arrays with mixed negative and positive numbers.
- Common mistake: Checking whether the element *value* at odd indices is even, or forgetting 0-based indexing.
Related Optum (UnitedHealth Group) questions
Collected from public candidate posts and coding forums. Updated Nov 2026.