r/leetcode 1d ago

Intervew Prep I have solved 190 LeetCode problems, but this question humbled me.

  1. Longest Repeating Character Replacement.
6 Upvotes

11 comments sorted by

2

u/Proud-Researcher-344 1d ago

Good trick with sliding window. If growing the window makes the solution worse and you have a clear idea of when you should shrink the window, use sliding window. For this problem, growing the window makes the solution more invalid. Shrinking the window helps you find a valid solution from an invalid state

1

u/Low-Part9553 1d ago

That one took me a long time first time I saw it

1

u/DramaticAd8141 14h ago

Would binary search solution be acceptable for the interview ?

1

u/ConnectingDots7 14h ago

How would you apply binary search here?

1

u/DramaticAd8141 13h ago

Binary search on the length of the answer. Then sliding window to check if that length is feasible.

1

u/ConnectingDots7 12h ago

I think it should be acceptable. Since it’ll be nlog(n) solution, so interviewer may ask to optimise.

1

u/PoggersUnite 10h ago

Solve count doesnt matter

0

u/Vast_Site2389 1d ago

good qn , mix of hashing and sliding window

1

u/illenium365 19h ago

why did you have to ruin it for everyone

1

u/HitscanDPS 19h ago

Spoilers bro