Day 20: Longest Repeating Character Replacement (LeetCode 424) — Sliding Window | O(n)
Автор: Ashwini Kemshetty
Загружено: 2026-01-30
Просмотров: 6
Описание:
🎯 Day 20 of My LeetCode Journey | Longest Repeating Character Replacement (LeetCode 424)
In this video, I solve LeetCode Problem #424 — Longest Repeating Character Replacement using a Sliding Window technique with frequency tracking for an optimal O(n) solution.
The task is to find the length of the longest substring where you can replace at most k characters to make all characters in the substring identical.
🔗 Problem Link:
https://leetcode.com/problems/longest...
📌 PROBLEM SUMMARY:
Given a string s and an integer k, return the length of the longest substring you can get after performing at most k character replacements so that the substring consists of only one repeated character.
✅ Example 1:
Input: s = "ABAB", k = 2
Output: 4
Explanation: Replace two ‘A’s or two ‘B’s to make "AAAA" or "BBBB".
✅ Example 2:
Input: s = "AABABBA", k = 1
Output: 4
Explanation: Replace the middle ‘A’ with ‘B’ → "AABBBBA", the longest repeating substring is "BBBB".
💡 KEY CONCEPTS:
✅ Sliding Window
✅ Frequency Map / Char Count
✅ Max Frequency tracking
✅ Two-pointer optimization
📊 COMPLEXITY:
• Time: O(n)
• Space: O(1) — constant alphabet size
🎓 DIFFICULTY: Medium
🏷️ TOPICS: String, Sliding Window, Two-Pointer
🔔 SUBSCRIBE for daily LeetCode solutions and coding challenges!
👍 LIKE if you enjoyed the approach!
💬 COMMENT your variations or questions below!
📚 MY LEETCODE JOURNEY PLAYLIST:
• Leetcode
🤝 CONNECT WITH ME:
• GitHub: https://github.com/ashwinikemshetty
• LinkedIn: / ashwinikemshetty
#LeetCode #LeetCode424 #SlidingWindow #String #Day20 #LongestRepeatingCharacterReplacement #100DaysOfCode #DSA #Algorithms
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: