educative.io

Input : abdcaab & k=2: How it is giving answer 4?

Hi, I think provided solution is not working with this input “abdcaab” and k=2
Can you explain please?


Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Longest Substring with Same Letters after Replacement (hard) - Grokking the Coding Interview: Patterns for Coding Questions

1 Like

Hi @PKAnshu, Thanks for reaching out to us.
The given solution is working fine with this input abdcaab and k=2.
Explanation: Replace the ‘dc’ with ‘aa’ to have the longest repeating substring “aaaa”.
Output: 4

Hope it will help, Happy Learning :slight_smile: