Reverse even numbers in a list
Problem Description
Given an integer array nums, the task is to process this array and return a new array containing only the even numbers from the original input, presented in reverse order. All odd numbers must be excluded from the final output.
Examples
- Input:
nums = [2, 3, 4] - Output:
[4, 2]
Clarifications
- The number
0is considered an even number. - If the input array contains no even numbers, the function should return an empty array.
AI interview prep
Core dilemma
Balancing optimal time and space complexity for array manipulation, especially considering potential constraints on memory or the desire for a single-pass solution, against the simplicity and readability of a multi-pass approach.
2 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Reverse even numbers in a list
Problem Description
Given an integer array nums, the task is to process this array and return a new array containing only the even numbers from the original input, presented in reverse order. All odd numbers must be excluded from the final output.
Examples
- Input:
nums = [2, 3, 4] - Output:
[4, 2]
Clarifications
- The number
0is considered an even number. - If the input array contains no even numbers, the function should return an empty array.