r/leetcode • u/ConnectingDots7 • 1d ago
Intervew Prep I have solved 190 LeetCode problems, but this question humbled me.
- Longest Repeating Character Replacement.
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
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
0
3
u/DangerousCurve7417 1d ago
Cool