Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Sliding Window Max Sum

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

Your question is Sliding Window Max Sum. 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

Uber Drivers analyzes consecutive trip records to identify the most valuable operating period. Given earnings and trip statuses in chronological order, find the maximum sum of eligible earnings in any window of exactly k records.

A record is eligible when its status is "completed" and its earnings are at least min_earnings. An eligible record contributes its earnings to the window sum. Ineligible records contribute 0, but still occupy positions in the window. A window is valid only if it contains at least min_eligible eligible records. Return the maximum sum among valid windows, or 0 if none exists.

Formal Specification

Implement max_eligible_window(earnings, statuses, k, min_earnings, min_eligible), where earnings is a list of non-negative integers and statuses is a same-length list of strings. Return an integer.

Constraints

  • 1 <= len(earnings) = len(statuses) <= 10^5
  • 1 <= k <= len(earnings)
  • 0 <= earnings[i] <= 10^6
  • 0 <= min_earnings <= 10^6
  • 0 <= min_eligible <= k
  • Each status is either "completed" or "canceled"

Function Signature

def max_eligible_window(earnings, statuses, k, min_earnings, min_eligible):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output