Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Algorithm Implementation

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

Your question is Algorithm Implementation. 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

Bosch IoT Suite services maintain alert IDs in ascending order for efficient lookup. Given a sorted list of integer alert IDs and a target ID, return the target's zero-based index using binary search. Return -1 if the target is not present.

Formal Specification

Implement search_alert_id(alert_ids, target).

  • Input: alert_ids, a list of integers sorted in non-decreasing order, and target, an integer.
  • Output: The zero-based integer index of target, or -1 when no matching ID exists.
  • If the target appears more than once, return any valid matching index.
  • The input list must not be modified.

Constraints

  • 0 <= len(alert_ids) <= 10^5
  • -10^9 <= alert_ids[i], target <= 10^9
  • alert_ids is sorted in non-decreasing order
  • The input list must not be modified

Function Signature

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