Template that works for ALL binary search problems
password
URL
type
status
date
slug
summary
tags
category
icon
Find a template for binary search, without doubt about less than or equal to, return low or low + 1, just replace the condition for specific issue.

ATTENTION

  • The condition is written to minimize or maximize the result. For example, if you're looking for the first element that satisfies a property, you would write the condition to check if nums[mid] >= target.
  • The binary search will return the leftmost position where the condition is true (or the rightmost if modified for that use case).

Example

Find the first element in the array that is greater than or equal to target.