PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates competency in basic array manipulation, specifically filtering elements by parity and reversing their order while preserving no other ordering constraints.

  • medium
  • Upstart
  • Coding & Algorithms
  • Software Engineer

Reverse even numbers in a list

Company: Upstart

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given an integer array `nums`, remove all odd numbers and return the remaining even numbers in reverse order (preserving no other ordering constraints). Example: - Input: `nums = [2, 3, 4]` - Output: `[4, 2]` Clarifications: - `0` is even. - If no even numbers exist, return an empty array.

Quick Answer: This question evaluates competency in basic array manipulation, specifically filtering elements by parity and reversing their order while preserving no other ordering constraints.

Given an integer array `nums`, remove all odd numbers and return the remaining even numbers in **reverse order** of their appearance in the original array. In other words, scan the array from right to left and collect every even value you encounter. **Example:** - Input: `nums = [2, 3, 4]` - Output: `[4, 2]` **Clarifications:** - `0` is even. - Negative even numbers (e.g. `-2`) count as even. - If no even numbers exist, return an empty array. - Duplicate even values are all kept.

Constraints

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

Examples

Input: ([2, 3, 4],)

Expected Output: [4, 2]

Explanation: Scanning right-to-left: 4 (even, keep), 3 (odd, skip), 2 (even, keep) -> [4, 2].

Input: ([],)

Expected Output: []

Explanation: Empty input yields an empty result.

Input: ([1, 3, 5, 7],)

Expected Output: []

Explanation: No even numbers, so the result is empty.

Input: ([0, 2, 4, 6],)

Expected Output: [6, 4, 2, 0]

Explanation: All even; reversed order is 6, 4, 2, 0. Note 0 is even.

Input: ([2, 2, 3, 2],)

Expected Output: [2, 2, 2]

Explanation: Duplicate evens are all kept; the odd 3 is removed.

Input: ([-4, -3, -2, 1],)

Expected Output: [-2, -4]

Explanation: Negative evens count: right-to-left gives -2, then -4.

Input: ([5],)

Expected Output: []

Explanation: Single odd element produces an empty result.

Input: ([8],)

Expected Output: [8]

Explanation: Single even element is returned as-is.

Hints

  1. Iterate over the array from the last element to the first.
  2. Keep only the values that are divisible by 2 (use the modulo operator: x % 2 == 0). Remember that 0 and negative numbers can be even too.
  3. Equivalently, filter the evens first then reverse the result — both give the same order.
Last updated: Jun 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Maximum Eastbound City Visits and Parse CSV - Upstart (medium)
  • Implement Byte Formatting and Cafeteria Billing - Upstart (medium)
  • Implement Three Assessment Functions - Upstart (medium)
  • Solve Five OA Coding Tasks - Upstart (medium)
  • Solve Reported OA Coding Problems - Upstart (medium)