Trains the technique from
LeetCode 424Longest Repeating Character ReplacementThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A contractor is freshening up a fence. panels is a string of uppercase letters read left to right, one letter per panel, naming the colour that panel carries today. There is enough paint on the truck to recoat at most budget panels, and a recoated panel may be given whichever colour the contractor likes.
Report the greatest number of neighbouring panels that can end up sharing a single colour once at most budget of them have been recoated. Leftover paint may go unused, and the panels chosen for recoating need not sit next to one another.
Example 1
Recoating the G at position 3 leaves positions 3 through 6 all showing H, a stretch of 4. No stretch of 5 can be evened out with a single recoat.
Example 2
Every stretch of 4 here holds two colours in equal share, so it would need two recoats. Recoating the L at position 2 gives three consecutive K panels.
Example 3
The fence is already one colour, so the whole run of 4 qualifies and the paint stays on the truck.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def longest_uniform_run(panels: str, budget: int) -> int:public int longestUniformRun(String panels, int budget)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.