FastPrepFastPrep
Problem Brief

Filter Odds and Reverse Evens

FULLTIMEOA

You are given an integer array nums.

Remove every odd value, then return the remaining even values in reverse order.

Function Description

Complete the function filterOddsAndReverseEvens in the editor below.

filterOddsAndReverseEvens has the following parameter:

  1. int[] nums: the input array

Returns

int[]: the even values from nums, reversed.

1Example 1

Input
nums = [1, 2, 3, 4, 6]
Output
[6, 4, 2]
Explanation

After removing odd values, the remaining array is [2, 4, 6]. Reversing it gives [6, 4, 2].

2Example 2

Input
nums = [7, 9, 11]
Output
[]
Explanation

Every value is odd, so the result is empty.

Constraints

Limits and guarantees your solution can rely on.

  • 1 <= nums.length <= 2 * 10^5
  • -10^9 <= nums[i] <= 10^9
public int[] filterOddsAndReverseEvens(int[] nums) {
    // write your code here
}
Input

nums

[1, 2, 3, 4, 6]

Output

[6, 4, 2]

Sign in to submit your solution.