Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find First Matching Event Timestamp

EasyPython00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the Python screen.

The question is on your right: Find First Matching Event Timestamp. Read through the requirements first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

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