dsa2 min read
Fruit Into Baskets [Medium] — Longest Subarray with 2 Distinct
Find the maximum fruits you can collect starting from any tree with two baskets (at most 2 distinct fruit types) using a sliding window.
Read →
1575 articles
Find the maximum fruits you can collect starting from any tree with two baskets (at most 2 distinct fruit types) using a sliding window.
Find the maximum sum of a subarray with all unique elements using a sliding window backed by a HashSet.
Find the smallest subarray with sum >= target using a variable sliding window that shrinks from the left when the condition is met.
Count tuples (i,j,k,l) where nums1[i]+nums2[j]+nums3[k]+nums4[l]=0 by hashing all pairs from first two arrays.
Maximize water trapped between two vertical lines using inward two pointers that always move the shorter line inward.