dsa1 min read
Russian Doll Envelopes — Sort + LIS Binary Search
Find the maximum number of nested envelopes by sorting by width ascending then height descending, then applying LIS.
Read →
webcoderspeed.com
5 articles
Find the maximum number of nested envelopes by sorting by width ascending then height descending, then applying LIS.
Master 1D DP: Fibonacci/Climbing Stairs, House Robber, LIS, Coin Change, Jump Game, and Kadane patterns with 5-language templates.
Find the length of the longest strictly increasing subsequence. O(n²) DP or O(n log n) patience sorting with binary search.
Maximum envelopes you can nest. Sort by width ascending and height descending, then LIS on heights. Descending heights prevents using same-width twice.
Count all LIS of maximum length. DP: track length and count. Segment tree on values enables O(n log n) solution.