23Implement binary search and its variants (first/last occurrence, search in rotated array).▼medium★ EssentialGoogleMetaAmazon1 replies◆ premiumBinary search is easy to describe and famously easy to get wrong (off-by-one, infinite loops). The signal is a correct template plus the variants (boundaries, rotated arrays) that come up constantly. Here is the answer.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 →