18Merge overlapping intervals, and explain the sort-then-sweep pattern.▼medium★ EssentialGoogleMetaAmazon1 replies○ sign inMerging intervals is a staple that probes the sort-then-sweep idea. The tell is sorting by start and merging in a single pass, O(n log n). Below is the pattern along with the family of problems it opens up.Open full answer →
46Gas Station: the greedy circuit problem.▼mediumGoogleAmazonMeta1 replies◆ premiumGas Station pays off 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 within it.Open full answer →
47Jump Game: can you reach the end of the array (greedy)?▼mediumGoogleMetaAmazon2 replies◆ premiumJump Game pays off spotting that a greedy reachability scan beats DP. Interviewers look for tracking the farthest reachable index in one pass, and catching 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 entry point to the whole interval family. The trick is sorting by start so overlaps end up 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 →
110Kruskal'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 one 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 →