Report the Tallest Stack After Each Block Drop in a Stacking Game

Last updated: November 29, 2026

Quick Overview

Square blocks are dropped one at a time onto a number line; block i has left edge left[i] and side length size[i], falls straight down, and lands on the floor or on the highest block that overlaps its horizontal span (touching edges do not count). After each drop, return the height of the tallest stack.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Square blocks are dropped one at a time onto a number line; block i has left edge left[i] and side length size[i], falls straight down, and lands on the floor or on the highest block that overlaps its horizontal span (touching edges do not count). After each drop, return the height of the tallest stack.

A Google onsite simulation problem that first checks a correct O(n^2) model of overlaps, then whether you can move to a coordinate-compressed segment tree with range max and range assignment. Interviewers care about the open interval overlap rule.

What the Interviewer Expects
  • Model each landed block as an interval with a top height
  • Use half-open spans so touching edges do not overlap
  • Compute landing height as max top over overlapping intervals
  • Maintain the running maximum for the answer
  • Describe the segment tree with coordinate compression for large n
Key Topics to Cover
simulation
intervals
segment tree
coordinate compression
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Implement the segment tree version with lazy range assignment.
  • What if blocks can be rectangles with different heights and widths?
  • How would you also return the number of separate stacks after each drop?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list of [left, size]. Each block occupies [left, left + size) horizontally. It lands at height base = max(top of every placed block overlapping that span, default 0) and its top becomes `...

High-Level Design

Keep placed, a list of (l, r, top). For a new block [L, R), scan placed blocks with l < R and L < r to find the base. Append the new block and update the running answer. This is quadratic but ...


Submit Your Answer
Markdown supported