From 00b5e44302eb0e846a0afe40cc25d2f1152214f3 Mon Sep 17 00:00:00 2001 From: Deepak ojha <59064357+Deepak3493@users.noreply.github.com> Date: Tue, 23 Jun 2026 02:48:42 +0530 Subject: [PATCH] Implement characterReplacement method in Java Added Java implementation for character replacement problem. --- ...03.LongestRepeatingCharacterReplacement.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/03. Sliding Window/03.LongestRepeatingCharacterReplacement.md b/03. Sliding Window/03.LongestRepeatingCharacterReplacement.md index 9949820..8cb4c48 100644 --- a/03. Sliding Window/03.LongestRepeatingCharacterReplacement.md +++ b/03. Sliding Window/03.LongestRepeatingCharacterReplacement.md @@ -63,3 +63,27 @@ class Solution { } } ``` + +```java +class Solution { + public int characterReplacement(String s, int k) { + int[] freqArray=new int[26]; // Storing Frequency of characters A-Z + int left=0, maxFreq=0,longestSubstring=0; + for(int right=0;rightk then we shrink win until it becomes valid agn + while((right-left+1)-maxFreq>k){ + freqArray[s.charAt(left)-'A']--;// Remove left character from window + left++; + } + //cal longest substing length + longestSubstring=Math.max(right-left+1,longestSubstring); + } + return longestSubstring; + + } +} +```