Skip to content

Latest commit

 

History

History
191 lines (141 loc) · 3.16 KB

File metadata and controls

191 lines (141 loc) · 3.16 KB

14 - Longest Repeating Character Replacement

Jira Ticket: LND-127
LeetCode: https://leetcode.com/problems/longest-repeating-character-replacement
Pattern: Sliding Window
Difficulty: Medium
Status: To Do
Priority: Medium

Labels: Medium, Sliding_Window
Created: 2025-08-21
Last Updated: 2025-08-22


📝 Problem Statement

Problem URL: https://leetcode.com/problems/longest-repeating-character-replacement Problem Description: You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times. Return the length of the longest substring containing the same letter you can get after performing the above operations. Example 1: Input: s = "ABAB", k = 2 Output: 4 Explanation: Replace the two 'A's with two 'B's or vice versa. Example 2: Input: s = "AABABBA", k = 1 Output: 4 Explanation: Replace the one 'A' in the middle with 'B' and form "AABBBBA". The substring "BBBB" has the longest repeating letters, which is 4. Constraints: 1 <= s.length <= 10^5 s consists of only uppercase English letters. 0 <= k <= s.length Difficulty: Medium Category: Sliding Window


🤔 Initial Thoughts

Understanding the Problem

  • What are we asked to find/compute?
  • What are the inputs and outputs?
  • What are the edge cases?

Pattern Recognition

Why Sliding Window?

What clues in the problem point to this pattern?


💡 Approach

Brute Force (if applicable)

Idea:

Time Complexity: O(?)
Space Complexity: O(?)

Optimized Approach

Idea:

Algorithm Steps: 1. 2. 3.

Time Complexity: O(?)
Space Complexity: O(?)


🎨 Visual Explanation

Example: 

Step 1: 
Step 2: 
Step 3: 

💻 Implementation

# Your solution here
def solution():
    pass

Code Explanation


🧪 Test Cases

Test Case 1: Basic Example

Input: 
Expected Output: 
Actual Output: 
Status: ⏳ Not Tested

Test Case 2: Edge Case - Empty Input

Input: 
Expected Output: 
Actual Output: 
Status: ⏳ Not Tested

Test Case 3: Edge Case - Single Element

Input: 
Expected Output: 
Actual Output: 
Status: ⏳ Not Tested

📊 Complexity Analysis

Time Complexity: O(?)

Breakdown:

Space Complexity: O(?)

Breakdown:


🎓 Key Learnings

What I Learned

Mistakes I Made

Pattern Insights

  • When to use sliding window:
  • When NOT to use this pattern:

🔗 Similar Problems


📚 Resources


✅ Progress Checklist

  • Problem understood
  • Pattern identified
  • Brute force solution
  • Optimized solution
  • All test cases pass
  • Complexity analyzed
  • Code reviewed
  • Learnings documented
  • Jira ticket updated

Status: 🔴 Not Started
Last Updated: 2025-08-22