Skip to the code
cf.
+25 XP

#146 Longest Uniform Run After k Edits

medium

A seat map shows a row of seats as a string row of uppercase letters, one letter per seat class. An admin can change the class of at most k seats. A group booking wants the longest run of neighboring seats that all have the same class.

Write longestUniformRun(row, k) that returns the length of the longest run of one repeated letter that can be made by changing at most k letters.

Example 1

Input: row = "ABAB", k = 2
Output: 4

Change both As to B (or both Bs to A).

Example 2

Input: row = "AABABBA", k = 1
Output: 4

Change the A at index 3 to get BBBB from index 2 to 5.

Constraints

  • 0 <= row.length <= 100000
  • row contains uppercase letters A to Z.
  • 0 <= k <= row.length
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).