PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/eBay

Implement list and grid transformation tasks

Last updated: May 8, 2026

Quick Overview

This question evaluates skills in character classification, array and list manipulation, greedy repartitioning logic, and iterative grid simulation with simultaneous state updates and gravity effects.

  • medium
  • eBay
  • Coding & Algorithms
  • Software Engineer

Implement list and grid transformation tasks

Company: eBay

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given three independent coding tasks (as in an online assessment). Implement each as a separate function. ## 1) Uppercase–lowercase difference **Input:** A list of characters `chars` (each element is a 1-length string). **Output:** An integer equal to: \[ (\#\text{uppercase letters}) - (\#\text{lowercase letters}) \] **Notes:** - Use typical letter checks (e.g., `isupper()`, `islower()` semantics). - Non-letters (digits, punctuation, whitespace, etc.) do not affect the result. --- ## 2) Repartition numbers into two lists, then merge **Input:** An integer array `nums`. **Process:** Iterate `nums` from left to right and build two lists `A` and `B`. For each number `x`: 1. Let `maxA` be the maximum value currently in `A` (or \(-\infty\) if `A` is empty). Let `maxB` be the maximum value currently in `B` (or \(-\infty\) if `B` is empty). 2. If `maxA > x` **or** `maxB > x`, append `x` to the list whose current maximum is larger: - if `maxA >= maxB`, append to `A`; else append to `B`. 3. Otherwise (i.e., `x` is at least as large as both current maxima), append `x` to the **shorter** list (if tied, append to `A`). **Output:** Return the concatenation `A + B`. --- ## 3) Balloon explosion in an n×n grid with gravity **Input:** An `n × n` integer matrix `grid` where each positive integer represents a balloon color/label, and `0` represents an empty cell. **Explosion rule (4-neighborhood):** For any cell `(r, c)` with value `v > 0`, count how many of its **up/down/left/right** neighbors also have value `v`. If that count is **≥ 2**, then the balloon at `(r, c)` explodes. - All explosions in a round happen **simultaneously** (decide based on the grid state at the start of the round). - Exploded cells become `0`. **Gravity rule:** After explosions, apply gravity column by column: within each column, all non-zero values fall downward to fill empty spaces, preserving their relative order (stable fall). **Repeat:** Repeat “explosion round → gravity” until a full round causes **no explosions**. **Output:** Return the final stabilized grid. **Clarifications:** - Only 4-direction adjacency counts (no diagonals). - Edge cells have fewer neighbors.

Quick Answer: This question evaluates skills in character classification, array and list manipulation, greedy repartitioning logic, and iterative grid simulation with simultaneous state updates and gravity effects.

Related Interview Questions

  • Wildcard Dictionary Matching - eBay (medium)
  • Format Words into Fixed-Width Lines - eBay (medium)
  • Assign Ads to Browser Positions - eBay (medium)
  • Solve Dependency, Prefix, and Cache Problems - eBay (medium)
  • Implement an In-Memory File System - eBay (medium)
|Home/Coding & Algorithms/eBay

Implement list and grid transformation tasks

eBay logo
eBay
Jan 6, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
3
0
Practice Read
Loading...

You are given three independent coding tasks (as in an online assessment). Implement each as a separate function.

1) Uppercase–lowercase difference

Input: A list of characters chars (each element is a 1-length string).

Output: An integer equal to:

(#uppercase letters)−(#lowercase letters)(\#\text{uppercase letters}) - (\#\text{lowercase letters})(#uppercase letters)−(#lowercase letters)

Notes:

  • Use typical letter checks (e.g., isupper() , islower() semantics).
  • Non-letters (digits, punctuation, whitespace, etc.) do not affect the result.

2) Repartition numbers into two lists, then merge

Input: An integer array nums.

Process: Iterate nums from left to right and build two lists A and B. For each number x:

  1. Let maxA be the maximum value currently in A (or −∞-\infty−∞ if A is empty). Let maxB be the maximum value currently in B (or −∞-\infty−∞ if B is empty).
  2. If maxA > x or maxB > x , append x to the list whose current maximum is larger:
    • if maxA >= maxB , append to A ; else append to B .
  3. Otherwise (i.e., x is at least as large as both current maxima), append x to the shorter list (if tied, append to A ).

Output: Return the concatenation A + B.

3) Balloon explosion in an n×n grid with gravity

Input: An n × n integer matrix grid where each positive integer represents a balloon color/label, and 0 represents an empty cell.

Explosion rule (4-neighborhood): For any cell (r, c) with value v > 0, count how many of its up/down/left/right neighbors also have value v. If that count is ≥ 2, then the balloon at (r, c) explodes.

  • All explosions in a round happen simultaneously (decide based on the grid state at the start of the round).
  • Exploded cells become 0 .

Gravity rule: After explosions, apply gravity column by column: within each column, all non-zero values fall downward to fill empty spaces, preserving their relative order (stable fall).

Repeat: Repeat “explosion round → gravity” until a full round causes no explosions.

Output: Return the final stabilized grid.

Clarifications:

  • Only 4-direction adjacency counts (no diagonals).
  • Edge cells have fewer neighbors.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More eBay•More Software Engineer•eBay Software Engineer•eBay Coding & Algorithms•Software Engineer Coding & Algorithms
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
  • AI Coding 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.