This is the quintessential "binary search on the answer" problem — it teaches you to identify when the answer space is monotonic and searchable.
Enable JavaScript for the full StreamPrep guide.