Answer: Mastercard OA Question 2024 June | Sliding Window | on-campus

Answer · Posted Jun 2026

Solution: Longest Repeating Character Replacement — Sliding Window Approach We use a Variable-Size Sliding Window. The key insight is: a window of size windowSize is valid if the number of characters we need to replace (i.e., non-dominant characters) is <= k. This condition simplifies to: windowSize - maxFreq <= k, where maxFreq is the frequency of the most common character in the current window. Expand the right pointer and update the frequency count. Track maxFreq — the highest frequency of ...

The full answer & interview discussion are available to premium members.

Log in Create a free account