<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ramnayan</title>
    <description>The latest articles on DEV Community by ramnayan (@ram1234).</description>
    <link>https://dev.to/ram1234</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F559200%2Fbd036a1c-f0e5-40ba-9ac3-9ee2e187dbd2.jpeg</url>
      <title>DEV Community: ramnayan</title>
      <link>https://dev.to/ram1234</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ram1234"/>
    <language>en</language>
    <item>
      <title>Longest Repeating Character Replacement Explanation</title>
      <dc:creator>ramnayan</dc:creator>
      <pubDate>Sun, 26 Oct 2025 01:54:51 +0000</pubDate>
      <link>https://dev.to/ram1234/longest-repeating-character-replacement-4bb0</link>
      <guid>https://dev.to/ram1234/longest-repeating-character-replacement-4bb0</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmc99umxgt7ftqns187fa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmc99umxgt7ftqns187fa.png" alt=" " width="800" height="323"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm writing this post about an specific data structure and algorithm well known problem that is &lt;strong&gt;"Longest Repeating Character Replacement"&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I have tried to solve this problem with javascript and using two popular algorithm that is Two-Pointer &amp;amp; Sliding-Window.&lt;/p&gt;

&lt;p&gt;I hope you are aware of these two algorithms. if you don't know don't worry bellow i have  mention the blogs link you can explore or you can find on the google.&lt;/p&gt;

&lt;p&gt;Two Pointer - &lt;a href="https://www.geeksforgeeks.org/dsa/two-pointers-technique/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/dsa/two-pointers-technique/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sliding Window - &lt;a href="https://www.geeksforgeeks.org/dsa/window-sliding-technique/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/dsa/window-sliding-technique/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem start here********
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Example 1:&lt;/p&gt;

&lt;p&gt;Input: s = "ABAB", k = 2&lt;br&gt;
Output: 4&lt;br&gt;
Explanation: Replace the two 'A's with two 'B's or vice versa.&lt;br&gt;
Example 2:&lt;/p&gt;

&lt;p&gt;Input: s = "AABABBA", k = 1&lt;br&gt;
Output: 4&lt;br&gt;
Explanation: Replace the one 'A' in the middle with 'B' and form "AABBBBA".&lt;br&gt;
The substring "BBBB" has the longest repeating letters, which is 4.&lt;br&gt;
There may exists other ways to achieve this answer too.&lt;/p&gt;
&lt;h2&gt;
  
  
  Explanation*************
&lt;/h2&gt;

&lt;p&gt;Initialise the required variables left right maxLength maxChar and count.&lt;/p&gt;

&lt;p&gt;first loop start from string zero index that is right &amp;amp; right. left start when K become zero or (r-l+1)-maxChar&amp;gt;K condition true it means window shrinking.&lt;/p&gt;

&lt;p&gt;count variable stores the character frequency to find the maxChar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var characterReplacement = function(s, k) {
        if(s.length==1) return 1;
        let l=r=maxChar=maxLength=0;
        let count={};

        for(let r=0; r&amp;lt;s.length;r++){
             if(s[r] in count){
                ....
            }else ....;
            maxChar = Math.max(maxChar, count[s[r]]);
            while((r-l+1)-maxChar&amp;gt;k){
                .....
            }
            maxLength=Math.max(maxLength, (r-l+1));
        }
        return maxLength;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the my best approach that i have used if you have any suggestions please put your thought.&lt;/p&gt;

&lt;p&gt;Thanks for stay to the end👍🙈&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>slidingwindow</category>
      <category>twopointer</category>
    </item>
  </channel>
</rss>
