Binary Search
Template
https://leetcode.com/discuss/post/786126/python-powerful-ultimate-binary-search-t-rwv8/
int binary_search(vector<int>& input) { auto condition = []() -> bool { // 1. condition should matches the question requirement return false; } // 2. search_space should cover all possible answers to the question int left = min(search_space); int right = max(search_space); while (left < right) { int mid = left + (right - left) / 2; if (condition(mid)) { right = mid; } else { left = mid + 1; } } // after the while loop, left will be the minimum element satisfying condition return left; }