PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers

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.

Part 1: Uppercase–lowercase difference

Given a list of characters `chars`, return an integer equal to the number of uppercase letters minus the number of lowercase letters. Use standard letter checks like `isupper()` and `islower()`. Any non-letter character such as digits, punctuation, or spaces should not affect the result.

Constraints

  • 0 <= len(chars) <= 200000
  • Each element of `chars` is a string of length 1
  • Characters may be letters, digits, punctuation, whitespace, or other symbols

Examples

Input: (['A', 'b', 'C', 'd', '!'])

Expected Output: 0

Explanation: There are 2 uppercase letters and 2 lowercase letters, so the result is 2 - 2 = 0.

Input: ([])

Expected Output: 0

Explanation: An empty list contains no uppercase or lowercase letters.

Input: (['x', 'y', 'Z'])

Expected Output: -1

Explanation: Uppercase: 1 (`Z`), lowercase: 2 (`x`, `y`), so 1 - 2 = -1.

Input: (['1', ' ', '?'])

Expected Output: 0

Explanation: None of the characters are letters, so the score stays 0.

Input: (['M'])

Expected Output: 1

Explanation: A single uppercase letter contributes +1.

Hints

  1. Scan the list once and keep a running total.
  2. If a character is uppercase, add 1. If it is lowercase, subtract 1. Ignore everything else.

Part 2: Repartition numbers into two lists, then merge

You are given an integer array `nums`. Build two lists `A` and `B` by scanning `nums` from left to right. For each number `x`, let `maxA` be the maximum value currently in `A` (or negative infinity if `A` is empty), and let `maxB` be the maximum value currently in `B` (or negative infinity if `B` is empty). If `maxA > x` or `maxB > x`, append `x` to the list whose current maximum is larger; if `maxA >= maxB`, choose `A`, otherwise choose `B`. If `x` is at least as large as both current maxima, append it to the shorter list; if both lists have the same length, choose `A`. Return the concatenation `A + B`.

Constraints

  • 0 <= len(nums) <= 200000
  • -10^9 <= nums[i] <= 10^9
  • You should process the numbers in left-to-right order

Examples

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

Expected Output: [1, 3, 2, 4]

Explanation: 1 goes to A. 2 goes to B because it is at least both maxima and B is shorter. 3 goes to A on a length tie. 4 goes to B.

Input: ([])

Expected Output: []

Explanation: With no numbers, both lists stay empty.

Input: ([7])

Expected Output: [7]

Explanation: The first element goes to A because the lists are tied in length.

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

Expected Output: [2, 1, 1, 2, 2]

Explanation: This case checks both the larger-maximum rule and the tie-breaking rule when maxima are equal.

Input: ([3, 5, 2, 6, 1])

Expected Output: [3, 6, 1, 5, 2]

Explanation: 2 is appended to B because B has the larger current maximum, while 1 is appended to A because A's maximum becomes larger later.

Hints

  1. You do not need to recompute each list's maximum from scratch every time; keep the current maximum of `A` and `B` as you build them.
  2. There are two separate decision rules: one based on the current maxima, and one based on the current lengths.

Part 3: Balloon explosion in an n x n grid with gravity

You are given an `n x n` grid of integers. A positive integer represents a balloon color or label, and `0` represents an empty cell. In one explosion round, inspect every non-zero cell. A cell with value `v` explodes if at least 2 of its 4-directional neighbors (up, down, left, right) also have value `v`. All explosions in a round happen simultaneously. After exploding cells become `0`, apply gravity independently to each column so that all non-zero values fall downward, preserving their relative order within the column. Repeat this process until a full round causes no explosions, then return the final grid.

Constraints

  • 0 <= n <= 50
  • `grid` is an `n x n` matrix
  • 0 <= grid[r][c] <= 10^9
  • Only 4-directional neighbors count; diagonal cells do not

Examples

Input: ([])

Expected Output: []

Explanation: An empty grid is already stable.

Input: ([[7]])

Expected Output: [[7]]

Explanation: A single balloon has no neighbors, so it cannot explode.

Input: ([[1, 0, 0], [1, 2, 0], [1, 2, 2]])

Expected Output: [[0, 0, 0], [1, 0, 0], [1, 2, 2]]

Explanation: The middle `1` and the lower-left `2` explode in the first round. Then gravity pulls the remaining balloons down, and no further explosions occur.

Input: ([[1, 1, 1], [1, 1, 1], [1, 1, 1]])

Expected Output: [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

Explanation: Every balloon has at least 2 same-valued neighbors, so the whole grid explodes in one round.

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

Expected Output: [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]

Explanation: First the 2x2 block of `3`s explodes. Gravity then forms a 2x2 block of `2`s in the lower-right corner, which explodes in the next round.

Hints

  1. In each round, first collect all cells that should explode based on the grid at the start of that round. Do not update cells one by one during the scan.
  2. For gravity, process each column from bottom to top and write non-zero values downward to keep the fall stable.
Last updated: May 8, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • 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

  • 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)
  • Find top co-viewed products - eBay (hard)