DSA in Java #8 | Trapping Rain Water: from O(n²) to O(n) time and O(1) space
SyntaxPilot
0:00 / 0:00
DSA in Java #8 | Trapping Rain Water: from O(n²) to O(n) time and O(1) space
1 просмотр · 3 дн. назад
SyntaxPilot
25 подписчиков
1 просмотр · 3 дн. назад
DSA in Java: Episode 8 of SyntaxPilot's free DSA full course, with real-life examples for every concept. Trapping Rain Water: from O(n²) to O(n) time and O(1) space.
In this video you'll learn:
• The problem, with a real-life example
• Water on one bar = min(left max, right max) - height
• Brute force: scan both sides for every bar, and why it gets TLE
• Prefix max and suffix max arrays: O(n) time, O(n) space
• Two pointers: why the smaller side is already decided, O(1) space
• The overflow bug on big inputs, and the long fix
• The exclusive-max bug: negative water
• Time and space complexity of all three solutions
Every concept starts with a real-life example, then an animation and notes, then live code in the SyntaxPilot online compiler.
Practice free in the SyntaxPilot compiler (nothing to install): https://syntaxpilot.in/
Detailed notes for this episode (code, outputs, practice): https://claude.ai/artifact/3NFFnpsgo1...
Interactive animations: https://claude.ai/artifact/G8didLNQmc...
Chapters
00:00 Welcome
00:22 Today's agenda
00:45 Rain in the courtyard
01:42 Water on ONE tower
02:20 Brute force, and the time limit
04:07 Left max, right max arrays
06:24 Two pointers, O(1) space
07:56 Typed live, edge cases
09:29 Overflow and negative water
11:00 Complexity
11:22 Quick quiz
11:48 Recap and homework
12:19 Next episode
Next episode: Sliding window: longest substring without repeating characters
Post your homework and quiz answer in the comments, and subscribe for the full basic-to-master playlist, free.
#DSA #DSATutorial #SyntaxPilot