Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Binary Search for Target Frequency
00:00
5 left

Binary Search for Target Frequency

MediumPython

Problem

Given a sorted array of signal frequencies, write an efficient search algorithm to locate a specific target frequency.

Implement the function below. Return the first index where target appears, or -1 if it is absent. The array may contain duplicate frequencies and must not be modified.

Constraints

  • 0 <= frequencies.length <= 10^5
  • frequencies is sorted in nondecreasing order
  • -10^9 <= frequencies[i] <= 10^9
  • -10^9 <= target <= 10^9
  • The input array must not be modified

Function Signature

def search_frequency(frequencies, target):
Interviewer

Your question is Binary Search for Target Frequency. 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.