🚀 Day 15/60 — LeetCode Discipline Problem Solved: Longest Repeating Character Replacement (Revision) Difficulty: Medium Today’s session revisited a classic sliding window problem that focuses on maximizing a repeating character substring after performing at most k replacements. The challenge here is not just scanning the string, but intelligently maintaining a window where the number of characters that need replacement stays within the allowed limit. By tracking character frequencies and dynamically adjusting the window, the solution efficiently finds the longest valid substring. Problems like this beautifully demonstrate how combining frequency counting with sliding window logic can turn a brute-force approach into a clean linear-time solution. 💡 Focus Areas: • Strengthened variable-size sliding window technique • Practiced frequency array optimization • Improved window shrink/expand decision logic • Reinforced substring pattern recognition • Focused on writing efficient and readable code ⚡ Performance Highlight: Achieved ~89% runtime efficiency on submission. Each day of deliberate practice is sharpening my understanding of algorithmic patterns and strengthening problem-solving intuition. #LeetCode #60DaysOfCode #100DaysOfCode #DSA #SlidingWindow #Strings #Algorithms #DataStructures #ProblemSolving #CodingJourney #SoftwareEngineering #Programming #Developers #TechCareers
Longest Repeating Character Replacement LeetCode Solution
More Relevant Posts
-
Day 48 on LeetCode Minimum Size Subarray Sum 🎯✅ Today’s problem was a perfect application of the Sliding Window technique for optimizing subarray problems. 🔹 Approach Used in My Solution The goal was to find the smallest subarray length whose sum is greater than or equal to the target. Key idea in the solution: • Use two pointers low and high to maintain a dynamic window • Expand the window by moving high and adding elements to currentSum • Once the sum becomes ≥ target, start shrinking the window from the left (low) • Continuously update the minimum length during this process • If no valid subarray is found, return 0 This approach avoids brute force and ensures we process each element at most twice. ⚡ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 💡 Key Takeaways: • Mastered the Sliding Window technique for variable window size • Learned how to optimize subarray problems from O(n²) to O(n) • Reinforced handling dynamic window expansion and contraction #LeetCode #DSA #Algorithms #DataStructures #SlidingWindow #Arrays #TwoPointers #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Day 51 on LeetCode — Permutation in String 🔤✅ Today’s problem was a strong application of the Sliding Window + Frequency Count technique. 🔹 Approach Used in My Solution The goal was to check if any permutation of s1 exists as a substring in s2. Key idea in the solution: • Use two frequency arrays (size 26) to track character counts • Initialize frequencies for s1 and the first window of s2 • Compare both frequency arrays — if equal, permutation exists • Slide the window across s2: – Add incoming character – Remove outgoing character • Check for a match at each step This ensures we efficiently check all substrings of size k without recomputing frequencies. ⚡ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 💡 Key Takeaways: • Mastered sliding window with fixed-size frequency arrays • Learned how to efficiently detect anagram/permutation patterns • Reinforced optimizing from brute force to linear-time solutions #LeetCode #DSA #Algorithms #DataStructures #SlidingWindow #Strings #Hashing #FrequencyArray #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Day 49 on LeetCode — Defuse the Bomb 💣✅ Today’s problem focused on circular arrays and window-based summation. 🔹 Approach Used in My Solution The goal was to transform the array based on k by summing the next or previous elements in a circular manner. Key idea in the solution: • Handle three cases: – k > 0 → sum of next k elements – k < 0 → sum of previous k elements – k == 0 → all values become 0 • Used modulo arithmetic (% n) to handle circular traversal • For each index, computed the sum by iterating forward/backward 🧠 Insight & Optimization Thought: Initially solved it using a brute-force sliding window idea (O(n × k)), which works perfectly fine and is intuitive. However, this can be further optimized into a true sliding window approach with O(n) by reusing the previous window sum instead of recalculating it every time. ⚡ Complexity (Current Approach): • Time Complexity: O(n × |k|) • Space Complexity: O(n) 💡 Key Takeaways: • Understood how brute-force windowing can lead to optimized sliding window solutions • Practiced handling circular arrays with modulo operations • Learned to identify opportunities to optimize from O(n × k) → O(n) #LeetCode #DSA #Algorithms #DataStructures #SlidingWindow #Arrays #CircularArray #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Day 52 on LeetCode — Minimum Recolors to Get K Consecutive Black Blocks 🧩✅ Today’s problem was another clean application of the Sliding Window technique with optimization. 🔹 Approach Used in My Solution The goal was to find the minimum number of recolors (W → B) needed to get k consecutive black blocks. Key idea in the solution: • Treat it as finding a window of size k with minimum 'W' (white blocks) • Count the number of 'W' in the first window of size k • Slide the window across the string: – Remove the left character (if it was 'W') – Add the new right character (if it is 'W') • Keep track of the minimum changes required This avoids recomputation and ensures an efficient linear solution. ⚡ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 💡 Key Takeaways: • Strengthened understanding of fixed-size sliding window problems • Learned how to convert problems into min/max count in a window • Reinforced optimizing from brute force to O(n) solutions #LeetCode #DSA #Algorithms #DataStructures #SlidingWindow #Strings #TwoPointers #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Day 55 on LeetCode — Subarray Product Less Than K 📈✅ Today’s problem was a powerful application of the Sliding Window technique with multiplication-based constraints. 🔹 Approach Used in My Solution The goal was to count the number of contiguous subarrays where the product is less than k. Key idea in the solution: • Use two pointers l and r to maintain a dynamic window • Expand the window by multiplying the current element with prod • If prod ≥ k, shrink the window from the left by dividing elements • At each step, add (r - l + 1) to the count — representing all valid subarrays ending at r Also handled an important edge case: • If k ≤ 1, no valid subarray exists This approach ensures every element is processed efficiently without recomputation. ⚡ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 💡 Key Takeaways: • Strengthened understanding of sliding window with multiplicative conditions • Learned how to count subarrays efficiently using window size • Reinforced handling edge cases early for cleaner logic #LeetCode #DSA #Algorithms #DataStructures #SlidingWindow #TwoPointers #Arrays #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Day 57 on LeetCode Longest Repeating Character Replacement 🔤✅ Today’s problem was a powerful application of the Sliding Window technique with frequency tracking. 🔹 Approach Used in My Solution The goal was to find the longest substring where we can replace at most k characters to make all characters the same. Key idea in the solution: • Use a frequency array (size 26) to track character counts in the current window • Maintain a variable maxFreq → the highest frequency character in the window • Expand the window using r • If (window size - maxFreq) > k, shrink the window from the left (l) • Continuously update the maximum valid window size This works because we only care about keeping the window valid with at most k replacements. ⚡ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 💡 Key Takeaways: • Mastered sliding window with dynamic constraints • Learned how tracking max frequency optimizes decisions • Strengthened understanding of window validation logic #LeetCode #DSA #Algorithms #DataStructures #SlidingWindow #Strings #TwoPointers #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
🚀 Day 16/60 — LeetCode Discipline Problem Solved: Palindrome Number (Revision) Difficulty: Easy Today’s practice revisited a classic number-based problem — determining whether a given integer reads the same forward and backward. Even though the problem appears simple, it reinforces an important concept: recognizing symmetry in data and applying straightforward transformations to verify it efficiently. In this revision, the focus was on converting the integer into a comparable structure and checking whether the reversed representation matches the original value. 💡 Focus Areas: • Reinforced palindrome symmetry concepts • Practiced number-to-string transformations • Strengthened basic logical validation techniques • Focused on writing clear and readable code Consistent practice of even the simplest problems helps keep fundamental logic sharp and reliable. #LeetCode #60DaysOfCode #100DaysOfCode #DSA #Algorithms #ProblemSolving #Programming #CodingJourney #SoftwareEngineering #Developers #TechCareers
To view or add a comment, sign in
-
-
Day 60 on LeetCode Range Sum Query 2D (Immutable) 🧮✅ Today’s problem was a major step forward into 2D Prefix Sum, extending the 1D concept into matrices. 🔹 Approach Used in My Solution The goal was to efficiently answer multiple submatrix sum queries. Key idea in the solution: • Precompute a 2D prefix sum matrix where each cell stores the sum of elements from (0,0) to (i,j) • While building prefix: prefix[i][j] = matrix[i][j] + top + left - topLeft • For any query (row1, col1) to (row2, col2): Use inclusion-exclusion: total - top - left + topLeft This allows answering each query in constant time after preprocessing. ⚡ Complexity: • Preprocessing Time: O(m × n) • Query Time: O(1) • Space Complexity: O(m × n) 💡 Key Takeaways: • Learned how 2D prefix sums extend 1D cumulative logic • Understood inclusion-exclusion principle in matrices • Optimized multiple queries from O(n²) → O(1) per query 🔥 This unlocks powerful techniques for matrix-based problems! #LeetCode #DSA #Algorithms #DataStructures #PrefixSum #2DPrefixSum #Matrices #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Day 50 on LeetCode — Maximum Average Subarray I 📊✅ Half-century milestone! 🚀 Today’s problem was a classic and clean application of the Sliding Window technique. 🔹 Approach Used in My Solution The goal was to find the maximum average of a subarray of size k. Key idea in the solution: • First, compute the sum of the first window of size k • Then slide the window forward by: – Adding the next element – Removing the element leaving the window • Continuously update the maximum sum encountered • Finally, divide the maximum sum by k to get the result This avoids recomputing sums and ensures an efficient solution. ⚡ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 💡 Key Takeaways: • Mastered the fixed-size sliding window pattern • Learned how to optimize subarray sum problems • Reinforced thinking in terms of window reuse instead of recomputation #LeetCode #DSA #Algorithms #DataStructures #SlidingWindow #Arrays #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
20 of #100DaysOfCode Solved LeetCode 438 – Find All Anagrams in a String using the Sliding Window Technique. 🔹 Approach (Optimal – Sliding Window): Used frequency arrays and a fixed window of size k to track character counts efficiently. Time Complexity: O(n) Space Complexity: O(1) 💡 Key Learning: Sliding Window helps reduce repeated computation when dealing with contiguous subarrays/substrings. 📌 Always look for patterns where a fixed-size window can optimize brute force solutions. #leetcode #coding #cpp #datastructures #algorithms #programming #softwareengineering #slidingwindow #dsa #100DaysOfCode
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development