18Merge overlapping intervals, and explain the sort-then-sweep pattern.▼medium★ EssentialGoogleMetaAmazon1 replies○ sign inInterval merging is a classic that tests the sort-then-sweep insight. The signal is sorting by start, then merging in one pass, O(n log n). Here is the pattern and the family of problems it unlocks.Open full answer →
46Gas Station: the greedy circuit problem.▼mediumGoogleAmazonMeta1 replies◆ premiumGas Station rewards spotting a greedy invariant that turns O(n²) into O(n). Two facts carry the whole solution: total feasibility, and that a failed prefix lets you skip every start inside it.Open full answer →
47Jump Game: can you reach the end of the array (greedy)?▼mediumGoogleMetaAmazon2 replies◆ premiumJump Game rewards spotting that a greedy reachability scan beats DP. The signal is tracking the farthest reachable index in one pass, and detecting the exact moment you fall behind it.Open full answer →
89Merge all overlapping intervals and explain the sort-then-sweep line technique.▼mediumGoogleAmazonMeta1 replies◆ premiumMerging intervals is the gateway to the whole interval family. The trick is sorting by start so overlaps land next to each other, then collapsing them in one linear sweep. Here is the pattern and the sweep-line generalization behind it.Open full answer →
108Kruskal's algorithm: minimum spanning tree via sorted edges and union-find.▼mediumGoogleAmazonMicrosoft2 replies◆ premiumKruskal builds a minimum spanning tree by sorting edges and adding the cheapest that does not form a cycle, using union-find for the cycle check. The signal is the greedy cut property and why disjoint-set is the right tool. Here is the answer.Open full answer →