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.
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.
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.
def max_eligible_window(earnings, statuses, k, min_earnings, min_eligible):