23Implement binary search and its variants (first/last occurrence, search in rotated array).▼medium★ EssentialGoogleMetaAmazon1 replies◆ premiumBinary search is simple to explain and notoriously easy to botch (off-by-one, infinite loops). Interviewers look for a correct template plus the variants (boundaries, rotated arrays) that show up constantly. The answer follows.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 →