Champagne Tower - Problem

We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row. Each glass holds one cup of champagne.

Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it. When those glasses become full, any excess champagne will fall equally to the left and right of those glasses, and so on.

For example, after one cup of champagne is poured, the topmost glass is full. After two cups of champagne are poured, the two glasses on the second row are half full. After three cups of champagne are poured, those two cups become full - there are 3 full glasses total now.

Now after pouring some non-negative integer cups of champagne, return how full the jth glass in the ith row is (both i and j are 0-indexed).

Input & Output

Example 1 — Two Cups Poured
$ Input: poured = 2, query_row = 1, query_glass = 1
Output: 0.5
💡 Note: Pour 2 cups into top glass: glass[0][0] gets 1.0 (full), remaining 1.0 overflows equally to row 1. Each glass in row 1 gets 0.5.
Example 2 — One Cup Only
$ Input: poured = 1, query_row = 1, query_glass = 1
Output: 0.0
💡 Note: Only 1 cup poured fills the top glass completely. No overflow reaches row 1, so glass[1][1] remains empty.
Example 3 — Large Pour
$ Input: poured = 100000009, query_row = 33, query_glass = 17
Output: 1.0
💡 Note: With 100 million cups, champagne fills many levels completely. Glass at row 33, position 17 will be completely full.

Constraints

  • 0 ≤ poured ≤ 109
  • 0 ≤ query_glass ≤ query_row < 100

Visualization

Tap to expand
Champagne Tower Problem OverviewInput:2 cups pouredQuery: row 1, glass 11.0Row 0: Full0.50.5Row 1: Half full each0.50.5TARGETOutput:0.5Excess 1.0 cup flows down and splits equally: 1.0 ÷ 2 = 0.5 each
Understanding the Visualization
1
Input
2 cups poured, query glass at row 1, position 1
2
Process
Pour into top glass, overflow splits equally to row below
3
Output
Target glass contains 0.5 cups
Key Takeaway
🎯 Key Insight: Simulate the overflow process level by level, where each glass overflow splits equally between two glasses below
Asked in
Google 12 Facebook 8 Microsoft 6
125.0K Views
Medium Frequency
~25 min Avg. Time
2.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen