Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Large-Scale Search Patterns
00:00
5 left

Large-Scale Search Patterns

MediumPython

Problem

Implement efficient search patterns for large-scale data retrieval.

Given a nondecreasing sorted array values and a list of integer queries, return one [first, last] index range for each query. If a query does not appear, return [-1, -1]. The ranges must preserve query order. Use binary search so each query is processed without scanning the full array.

Constraints

  • 0 <= len(values) <= 100000
  • 0 <= len(queries) <= 10000
  • -10^9 <= values[i], queries[i] <= 10^9
  • values is sorted in nondecreasing order

Function Signature

def search_ranges(values, queries):
Interviewer

Your question is Large-Scale Search Patterns. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.