Skip to content
Y
yTube.SITE v8.0.4
media / worlds / tools / internet oddities
YouTube / video information

LeetCode 799 | Champagne Tower | Java | Medium | 2D D P & Cascade Simulation | CodeByTushu

Video information, playback and saved actions.

LeetCode 799 | Champagne Tower | Java | Medium | 2D D P & Cascade Simulation | CodeByTushu

Description: πŸš€ Welcome Back to CodeByTushu!

In today’s video, we solve LeetCode 799 β€” Champagne Tower using Dynamic Programming, Simulation, and Math in Java.

We are given a pyramid of glasses where the first row contains 1 glass, the second row contains 2 glasses, and each glass holds up to 1 cup of liquid. When champagne is poured into the topmost glass (0, 0), any excess liquid spills equally into the two adjacent glasses directly below it at row r + 1. We must determine how full the glass at index query_glass in query_row is after pouring a total of poured cups of champagne.

By modeling the downward liquid flow using a 2D dynamic programming grid, we can track the total volume of liquid that reaches each glass. For any glass receiving more than 1.0 cup, the overflowing liquid is calculated as (tower[r][c] - 1.0) / 2.0 and distributed evenly to its left child (r + 1, c) and right child (r + 1, c + 1). Because query_row is strictly less than 100, simulating up to query_row requires at most 5,050 constant-time transitions, yielding an optimal O(R^2) time complexity and O(R^2) auxiliary space that runs in under a millisecond.

πŸ”₯ Problem Highlights

βœ… Pyramid cascade modeling via state transition
βœ… Overflow recurrence: (tower[r][c] - 1.0) / 2.0 distributed equally downwards
βœ… Bottom-up row-by-row simulation up to query_row
βœ… Safe clamping min(1.0, tower[query_row][query_glass])
βœ… Optimal O(R^2) time complexity with at most 5,050 evaluations
βœ… Clean double grid implementation preventing floating-point drift

⏱️ TIMESTAMPS

00:00 Intro
01:06 Problem Understanding & Constraints
02:19 Pascal's Triangle Fluid Simulation Insight
03:50 2D Dynamic Programming Cascading Strategy
05:15 Java Code Walkthrough Line by Line
06:39 Test Cases Walkthrough & Simulation
08:08 Time Complexity Analysis (O(query_rowΒ²))
09:10 Space Complexity Analysis (O(query_rowΒ²))
09:56 Outro & Wrap-up

πŸ“‚ Problem Folder & Detailed Documentation:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/tree/main/solutions/February/14-February/799-Champagne-Tower

β˜• Java Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/February/14-February/799-Champagne-Tower/Solution.java

🐍 Python Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/February/14-February/799-Champagne-Tower/solution.py

⚑ C++ Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/February/14-February/799-Champagne-Tower/solution.cpp

🌐 JavaScript Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/February/14-February/799-Champagne-Tower/solution.js

πŸ”— LeetCode Source Code

πŸ“Œ Admin type the link

🌐 All LeetCode Solutions

πŸ“Œ https://codebytushu.com/Leetcode/

πŸ“± Join CodeByTushu on WhatsApp

Get coding updates, LeetCode solutions, daily questions and more.

https://whatsapp.com/channel/0029Vb8k5mCDeON2Xwlkxe40

❀️ Donate

πŸ“Œ https://codebytushu.com/Leetcode/donate.php

πŸ”₯ Perfect For

LeetCode Medium Problems
Java DSA Preparation
Dynamic Programming on Pyramids
Simulation Algorithms
Cascade Overflow Problems
Coding Interview Preparation
Problem Solving

🌐 Follow CodeByTushu

▢️ YouTube: https://www.youtube.com/@codebytushu

πŸ“Έ Instagram: https://instagram.com/codebytushu/

πŸ’Ό LinkedIn: https://www.linkedin.com/company/codebytushu/

🌍 Website: https://codebytushu.com

πŸ™ GitHub: https://github.com/CodeByTushu

❀️ Don’t Forget To

πŸ‘ Like | πŸ’¬ Comment | πŸ”” Subscribe

πŸ’¬ Question of the Day

Why does a glass at position (r, c) contribute to both (r + 1, c) and (r + 1, c + 1) equally?

1️⃣ Because gravity always pulls champagne towards the left
2️⃣ Because each glass is positioned directly atop the gap between two glasses in the row below, splitting overflow symmetrically in half
3️⃣ Because odd-indexed glasses cannot hold liquid
4️⃣ Because the capacity of each glass doubles on every successive row

#LeetCode799 #LeetCode #ChampagneTower #Java #JavaDSA #DynamicProgramming #Simulation #DSA #CodingInterview #ProblemSolving #LeetCodeMedium #DailyLeetCode #JavaProgramming #CodeByTushu

πŸ‘‡ Comment the answer below! πŸ”₯Β Close description
Β Β Β Β Β Β 
Videos related to "LeetCode 799 | Champagne Tower | Java | Medium | 2D D P & Cascade Simulation | CodeByTushu"