Sum of Subarray Minimums — Contribution Technique with Stack (LeetCode 907)
Solve Sum of Subarray Minimums using the contribution technique with monotonic stacks. Python solution with modular arithmetic, traces, and O(n) analysis.
277 posts · page 2 of 6
Solve Sum of Subarray Minimums using the contribution technique with monotonic stacks. Python solution with modular arithmetic, traces, and O(n) analysis.
Solve Trapping Rain Water (LeetCode 42) using a stack-based approach. Python code with detailed trace, comparison with two-pointer, and complexity analysis.
Validate Stack Sequences solved by simulating push and pop operations. Python solution with step-by-step trace, edge cases, and complexity analysis for LeetCode 946.
Solve advanced binary search on answer problems — Koko eating bananas, ship packages, split array largest sum, minimize max distance to gas station, and magnetic force between balls.
Learn how to flatten a binary tree to a linked list using preorder threading, Morris traversal, and how to convert a BST to a sorted doubly linked list — with full Python implementations and Big-O analysis.
Master BST iterator using stack-based controlled in-order traversal, range sum queries, counting nodes in range, closest value, and closest K values — with full Python implementations.
Master every knapsack variant — 0/1 knapsack, unbounded knapsack, fractional knapsack, subset sum, partition equal subset, and target sum with Python solutions and Big-O analysis.
Master longest subsequence problems — LIS with patience sorting, longest bitonic, chain of pairs, zigzag subsequence, Russian doll envelopes (2D LIS).
Master DP on grids — unique paths, minimum path sum, dungeon game, cherry pickup, and maximum path in grid with step-by-step Python solutions.
Master palindrome DP problems — longest palindromic subsequence, minimum cuts for palindrome partitioning, counting palindromic substrings, and shortest palindrome with KMP.
Complete guide to all stock trading problems — I through IV, with cooldown, and with transaction fee. One unified state machine DP framework covers them all.
The complete DSA interview checklist — 75 essential problems organized by pattern, study schedules for 4, 8, and 12 weeks, a pattern recognition framework, and what interviewers actually look for.
Master space optimization — rolling arrays for DP, in-place algorithms, bit manipulation as sets, Morris traversal, constant-space linked list operations, and Floyd's cycle detection.
Derive character ordering from sorted alien words using topological sort, with course schedule variants and prerequisite chain problems.
Learn how to check if a graph is bipartite using BFS 2-coloring and DFS, with applications in matching, scheduling, and conflict detection.
Learn to clone graphs with BFS and DFS, validate graph trees, find minimum height trees via centroid decomposition, and reconstruct itineraries with Hierholzer's algorithm.
Master finding connected components using DFS, BFS, and Union-Find with applications to counting islands and grid connectivity problems.
Learn how to detect negative cycles using Bellman-Ford's nth relaxation, SPFA algorithm, and apply it to arbitrage detection in currency exchange graphs.
Master flood fill, surrounded regions, number of enclaves, and Pacific Atlantic water flow using DFS and BFS grid traversal techniques in Python.
Master the top 20 graph interview patterns with a BFS vs DFS decision flowchart, Union-Find strategies, grid vs adjacency list trade-offs, and template code.
Explore MST applications in network design, clustering, and competitive programming with second-best MST, critical edges, and minimum cost to connect points.
Master shortest path algorithms on grids including BFS for unweighted grids, 0-1 BFS with deque, and Dijkstra for weighted terrain with obstacles and portals.
Solve word search with DFS backtracking, Boggle with Trie pruning, and word ladder with BFS for efficient string transformation problems.
Learn to add two numbers represented as linked lists — both reverse order (LeetCode 2) and forward order (LeetCode 445). Covers carry handling, different-length lists, and Python implementations with Big-O analysis.
Learn two approaches to deep copy a linked list with random pointers — HashMap O(n) space and the interleaving O(1) space technique. Step-by-step walkthroughs with Python code and Big-O analysis.
Learn to flatten a multilevel doubly linked list (LeetCode 430) and flatten sorted linked lists. Covers iterative and recursive DFS approaches with Python implementations and Big-O analysis.
Master the top 15 linked list interview patterns — dummy node, fast-slow pointers, reversal, merge, partition, and more. Includes common mistakes, a time complexity cheatsheet, and a decision flowchart.
Learn three ways to check if a linked list is a palindrome — stack-based O(n) space, reverse-second-half O(1) space, and recursive. Step-by-step walkthroughs with Python code and Big-O analysis.
Master linked list partitioning — partition around a value (LeetCode 86), odd-even rearrangement (LeetCode 328), segregate 0s/1s/2s, with full Python implementations and Big-O analysis.
Master the two-pointer gap technique to remove the nth node from the end in a single pass. Covers the dummy node trick, edge cases like removing the head and single-node lists, with Python code and Big-O analysis.
Learn how to reorder a linked list by interleaving first and last nodes — find the middle, reverse the second half, and merge alternating. Full Python code, step-by-step walkthrough, and Big-O analysis.
Master linked list rotation by K positions, swap nodes in pairs, and swap Kth nodes from both ends — full Python implementations, step-by-step traces, and Big-O analysis.
Master the monotonic stack pattern — next greater/smaller element, largest rectangle in histogram, maximal rectangle, trapping rain water, stock span, daily temperatures.
Master advanced prefix sum techniques — 2D prefix sums for submatrix queries, difference arrays for range updates in O(1), subarray sum divisible by K, XOR prefix, and more.
Understand skip lists — multi-level linked lists with probabilistic balancing that achieve O(log n) search, insert, and delete. Covers the concept, comparison with BSTs, Redis use case, and full Python implementation.
Master anagram problems — valid anagram checks, grouping anagrams by sorted and frequency keys, finding all anagrams in a string with sliding windows, and the minimum window substring problem.
Master string encoding and decoding — delimiter-based encode/decode, run-length encoding, decoding nested bracket strings with stacks, string compression, and serialization patterns.
Master string hashing for pattern matching — polynomial hashing, rolling hash for Rabin-Karp, double hashing, repeated DNA sequences, and longest duplicate substring.
A complete guide to string interview patterns — top 20 patterns, two-pointer on strings, frequency map technique, sliding window template, when to use Trie vs HashMap, common mistakes, and a complexity cheatsheet.
Sliding window on strings with reusable templates — longest substring without repeating, minimum window substring, K distinct characters, and permutation check.
Essential string manipulation tricks — reverse words, reverse vowels, string rotation check, repeated substring pattern, multiply strings, and add binary.
Master palindrome problems — longest palindromic substring with expand-around-center and Manacher's algorithm, counting palindromic substrings, and palindrome partitioning.
Master parentheses problems — validate with stacks, generate all combinations with backtracking, find the longest valid substring with DP and stack, remove invalid parentheses with BFS, and more.
Master string subsequence problems — check subsequences with two pointers, count distinct subsequences with DP, find the longest common subsequence, and build the shortest common supersequence.
Advanced Trie applications — autocomplete system, search suggestions, word break with Trie, longest word in dictionary, replace words, and magic dictionary.
Complete guide to boundary traversal — left boundary, leaf nodes, and right boundary in reverse. Multiple Python approaches with edge case handling.
Solve distance problems in binary trees — distance between two nodes, all nodes at distance K, burning a tree from a node, and sum of distances using rerooting. Full Python implementations.
The complete guide to binary tree interview patterns — top 20 patterns, DFS vs BFS decision guide, recursive vs iterative approaches, common mistakes, complexity cheatsheet, and template code.