How Full a Chosen Glass Is After Pouring Into a Pyramid
Last updated: November 29, 2026
Quick Overview
Glasses are stacked in a pyramid where row i has i + 1 glasses, each holding one cup. Pour a number of cups into the top glass; any excess beyond one cup splits equally into the two glasses below. Return how full the glass at (row, index) is, between 0 and 1.
0
0
0 solved
Glasses are stacked in a pyramid where row i has i + 1 glasses, each holding one cup. Pour a number of cups into the top glass; any excess beyond one cup splits equally into the two glasses below. Return how full the glass at (row, index) is, between 0 and 1.
A Google technical screen simulation that models overflow propagation, similar in spirit to load spilling through tiers of servers. Interviewers look for row-by-row flow simulation rather than recursion with repeated work, and the clamp to one cup at the end.
What the Interviewer Expects
- Simulate total flow through each glass row by row
- Pass (flow - 1) / 2 to each child only when flow exceeds 1
- Use a single row array to keep space O(rows)
- Clamp the final answer to at most 1
- Avoid recursion that recomputes overlapping subproblems
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How many cups are needed before the glass at (row, index) starts to fill?
- What if the left child receives twice as much overflow as the right?
- How would you handle glasses with different capacities?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: poured (non-negative number), row and index with 0 <= index <= row < 100. Output a float in [0, 1]. Pouring is instantaneous: we only care about the final steady state....
High-Level Design
Track flow[j], the total liquid that passes through glass j of the current row (it may exceed one). Start with [poured]. For each row up to the target row, build the next row: for each glass with ...