Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Python Algorithm Implementation

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

Your question is Python 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

Motion Recruitment Partners stores candidate assessment scores in nondecreasing order. Implement a function that returns the index of the first occurrence of a target score using binary search. Return -1 when the target does not appear.

If the target occurs multiple times, return the smallest valid index. The input list must not be modified.

Formal Specification

  • Input: scores, a sorted list of integers, and target, an integer.
  • Output: An integer containing the first index where scores[index] == target, or -1 if no such index exists.

Constraints

  • 0 <= len(scores) <= 10^5
  • -10^9 <= scores[i], target <= 10^9
  • scores is sorted in nondecreasing order
  • Duplicate scores are allowed

Function Signature

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