Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Efficient Logic Coding Challenge

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

Your question is Efficient Logic Coding Challenge. 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 Google Cloud Dataflow worker receives an ordered list of event labels. Given events and a set of required labels, return the shortest contiguous range of events that contains every required label at least once.

Return the range as [start, end], using inclusive zero-based indices. If no range contains all required labels, return [-1, -1]. If multiple ranges have the same minimum length, return the one with the smallest starting index.

Formal Specification

  • Input: events, a list of strings, and required, a list of distinct strings.
  • Output: A two-element list [start, end] of integers, or [-1, -1] when no valid range exists.
  • A valid range must contain every string in required at least once.

Constraints

  • 1 <= len(events) <= 10^5
  • 1 <= len(required) <= 10^4
  • Each event label is a non-empty string of length at most 50
  • required contains distinct labels
  • Return the earliest range when multiple minimum-length ranges exist

Function Signature

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