Longest Repeating Character Replacement - Sliding Window - Leetcode Medium - JAVA

  Рет қаралды 11,665

Code With Ease - By Varsha

Code With Ease - By Varsha

Күн бұрын

Пікірлер: 18
@suhasdevang9332
@suhasdevang9332 Жыл бұрын
awesome explanation ma'am, Great job
@codewithease-byvarsha
@codewithease-byvarsha 10 ай бұрын
Thanks. You will be thrilled to know that, along with our regular content, you can now get something extra. As part of our KZbin channel memberships, we will be offering a variety of exclusive perks, including virtual video collaborations, member-only polls, and premium content exclusively for our members. Whether it's dedicated interview questions on Java threads and concurrency, a deep dive into system design components, or detailed Spring Boot project plans, all this exclusive content is just for you. Ready to become a valued member? Click this link - kzbin.info/door/iWsQBA97JYGntWs99ZrQmwjoin
@AbhishekKumar-dm6ss
@AbhishekKumar-dm6ss Жыл бұрын
Great Explanation👏👍🏻👍🏻👌
@venkateshhs3776
@venkateshhs3776 11 ай бұрын
Thank you.
@codewithease-byvarsha
@codewithease-byvarsha 10 ай бұрын
You're welcome! If you could spare 3 mins to help this channel grow further, kindly nominate me here for National Creator Awards. For more details : tinyurl.com/bdhuj237
@anulipidas8300
@anulipidas8300 Жыл бұрын
👍👍👍👍good👍👍👍
@_akashchaudhary
@_akashchaudhary Жыл бұрын
undercooked food served
@nikhilkumarjamwal5322
@nikhilkumarjamwal5322 Жыл бұрын
for non-repeat why did we not use while loop? can you explain it?
@codewithease-byvarsha
@codewithease-byvarsha Жыл бұрын
Great question, there's a catch. Firstly, in the github link, if you notice "nonrepeat" is a variable which is calculated in the previous line, if you use a while loop even if left pointer is incremented the value of nonrepeat stays the same and can cause IndexOutOfBounds Exception. Coming to the question of while vs if, it is essentially the same thing because you effectively need to shrink the window by 1 character as it is at most k times, even if you use a while loop, it will run only once and next time it will become equal to k which is fine as we need at most k. Try few testcases with a dry-run and use a while loop you will get it.
@_DEBANJANDHAR
@_DEBANJANDHAR 9 ай бұрын
public class LongRepeatCharReplace { static int longestsubstring(String s, int k){ int alphabet[] = new int[26]; int maxRepeatingChar = 0; int maxLength = 0; int left = 0; for(int right = 0; right < s.length(); right++){ char ch = s.charAt(right); alphabet[ch - 'A']++; maxRepeatingChar = Math.max(maxRepeatingChar, alphabet[ch - 'A']); //Window size -> right-left+1 int needReplacement = right-left+1 - maxRepeatingChar; while(needReplacement > k){ alphabet[s.charAt(left) - 'A']--; left++; needReplacement = right-left+1 - maxRepeatingChar; } maxLength = Math.max(maxLength, right-left+1); } return maxLength; } public static void main(String[] args) { String s = "AABABBA"; int k = 1; int ans = longestsubstring(s, k); System.out.println(ans); } }
@Brute_Coder
@Brute_Coder Жыл бұрын
IDK Why ......you explained the approach well but then you just took a naive testcase and explained that .... not getting into the internal working of the algo ....
@codewithease-byvarsha
@codewithease-byvarsha Жыл бұрын
You are right, I agree, I could have used a better example for the dry-run. Thanks for your feedback!
@parassaharan4143
@parassaharan4143 2 ай бұрын
@@codewithease-byvarsha nahh it's good
@rishavkalra3843
@rishavkalra3843 11 ай бұрын
thanks mam
@codewithease-byvarsha
@codewithease-byvarsha 10 ай бұрын
Most welcome 😊 If you could spare 3 mins to help this channel grow further, kindly nominate me here for National Creator Awards. For more details : tinyurl.com/bdhuj237
@surajsidar3280
@surajsidar3280 5 ай бұрын
Start of the video is not good. I know you are trying to give a preview of the video. (Entertainment and Infotainment do like this) When I played the video I thought how can someone start without even reading the question.
@ManishGupta-wb2wc
@ManishGupta-wb2wc 7 ай бұрын
that was the worst explanation bro
@Venom-oy1wq
@Venom-oy1wq Жыл бұрын
try to explain the code .......not so good
Can you implement a LINEAR Queue using Array? 🤔  | DSA | JAVA
12:06
Code With Ease - By Varsha
Рет қаралды 154
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Longest Repeating Character Replacement - Leetcode 424 - Python
20:44
longest substring without repeating characters in java
18:13
Software Engineering Job Interview - Full Mock Interview
1:14:29
freeCodeCamp.org
Рет қаралды 1,6 МЛН
DHH discusses SQLite (and Stoicism)
54:00
Aaron Francis
Рет қаралды 105 М.
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН