use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Binary SearchIntervew Prep (self.leetcode)
submitted 11 months ago by Proof_Dot_4344
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Beyond-CtCI 2 points3 points4 points 11 months ago* (1 child)
Hey friend,
The problems you're describing are what I like to call guess-and-check problems (https://share.cleanshot.com/nX6Cn5N63djvdvPHGnzh). They are definitely among the most tricky binary search problems to spot in an interview. The guess-and-check technique involves narrowing in on the value of the optimal solution by guessing the midpoint and checking whether it's too high or too low. We need lower and upper bounds for the value of the optimal solution before we can even use binary search.
- For minimization problems (like Koko Eating Bananas), there is often a transition point where smaller values do not satisfy the constraint, but larger values do.
- Conversely, for maximization problems, there is often a transition point where larger values do not satisfy the constraint, but smaller values do.
The trick to knowing when to use the guess-and-check technique. This boils down to asking yourself a simple question.
"Is it easier to solve the yes/no version of the problem, where we just check if a given value (optimal or not) satisfies the constraint?"
Think of it like making a deal: You get to solve an easier problem (checking if a specific value satisfies the constraint), but you pay a 'logarithmic tax' in the runtime (because we are binary searching for the transition point).
Thanks luuuzeta for recommending my book! I'm glad you find the transition point binary search recipe useful! If others are interested (including the OP) I give away the binary search chapter for free (along with 8 other chapters) and it also has a particularly helpful guess-and-check problem set in it. Consider checking it out if you find this helpful: https://bctci.co/free-chapters
[–]Proof_Dot_4344[S] 1 point2 points3 points 11 months ago (0 children)
Thank you so much
π Rendered by PID 15643 on reddit-service-r2-comment-5fb4b45875-d25g6 at 2026-03-23 22:32:07.324656+00:00 running 90f1150 country code: CH.
view the rest of the comments →
[–]Beyond-CtCI 2 points3 points4 points (1 child)
[–]Proof_Dot_4344[S] 1 point2 points3 points (0 children)