Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find First Matching Event Timestamp

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

Your question is Find First Matching Event Timestamp. 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

In a Google Photos mobile client, event timestamps may arrive unsorted after local batching. Given an integer array timestamps and an integer target, return the index of the first occurrence of target after sorting the array in non-decreasing order. If target does not exist, return -1.

Formal Specification

  • Input: timestamps is a list of integers. target is an integer.
  • Output: Return an integer representing the leftmost index of target in the sorted version of timestamps, or -1 if not found.

Constraints

  • 1 <= len(timestamps) <= 10^5
  • -10^9 <= timestamps[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Search should be performed with binary search after sorting

Function Signature

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