Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Basic Algorithm Implementation

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

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

A MONOPOLY GO! leaderboard stores player scores in strictly increasing order. Given the sorted scores and a target score, return the index of the target using binary search. Return -1 if the target is not present.

Formal Specification

Implement search_score(scores, target).

  • scores is a list of integers sorted in strictly increasing order.
  • target is an integer score to locate.
  • Return an integer index from 0 through len(scores) - 1 when target exists.
  • Return -1 when target does not exist.
  • Do not modify scores.

Constraints

  • 0 <= len(scores) <= 100,000
  • -10^9 <= scores[i], target <= 10^9
  • scores is strictly increasing
  • The input list must remain unchanged

Function Signature

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