Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

O(n) String or Array Algorithm

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

Your question is O(n) String or Array Algorithm. 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

DoorDash delivery status streams can contain short periods of inconsistent updates. Given a string of status codes, find the length of the longest contiguous segment that can be changed into one repeated status code using at most k replacements.

You may replace any character in the selected segment, and different positions may be replaced with different characters. Return only the maximum achievable length.

Formal Specification

Implement longest_status_window(statuses, k), where statuses is a string and k is a nonnegative integer. Return an integer representing the longest contiguous substring that can be made uniform with at most k replacements.

Constraints

  • 1 <= len(statuses) <= 100,000
  • statuses contains only uppercase English letters
  • 0 <= k <= len(statuses)
  • The answer is at least 1

Function Signature

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