Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Smallest Number Above Lower Bound

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Smallest Number Above Lower Bound. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Airbnb search results may contain nightly prices sorted in nondecreasing order. Given a sorted list of prices and a lower bound, find the smallest price that is strictly greater than that bound.

Return -1 if no price satisfies the requirement.

Formal Specification

Implement find_smallest_greater(prices, lower_bound).

  • prices is a sorted list of integers in nondecreasing order.
  • lower_bound is an integer threshold.
  • Return the smallest integer in prices such that price > lower_bound.
  • If every price is less than or equal to lower_bound, return -1.

Because the list is sorted, use binary search rather than scanning every price.

Constraints

  • 0 <= len(prices) <= 10^5
  • -10^9 <= prices[i], lower_bound <= 10^9
  • prices is sorted in nondecreasing order
  • Duplicate prices may appear

Function Signature

def find_smallest_greater(prices, lower_bound):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output