FastPrepEven Values at Even Indices

Even Values at Even Indices

Microsoft logoMicrosoft● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

Given an integer array nums, return every value whose zero-based index is even and whose value is also even.

Preserve the values' original order.

Function

evenValuesAtEvenIndices(nums: int[]) → int[]

Examples

Example 1

nums = [2,3,4,6,8]return = [2,4,8]

Indexes 0, 2, and 4 are even, and their values are also even.

Example 2

nums = [1,2,3,4]return = []

The values at even indexes are 1 and 3, so neither is returned.

Constraints

  • 0 <= nums.length <= 100000
  • -10^9 <= nums[i] <= 10^9

More Microsoft problems

See Microsoft hiring insights
public int[] evenValuesAtEvenIndices(int[] nums) {
  // Write your code here.
}
nums[2,3,4,6,8]
expected[2,4,8]
Checking account…