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

Sdílet
Vložit
  • čas přidán 19. 08. 2023
  • #CorejavaInterviewquestions #CodingInterviews #DataStructuresAndAlgorithms #ProblemSolving
    #TechInterviews #JavaProgramming #CodeWithEaseByVarsha
    #TechnicalInterviews #CareerGrowth #JobPreparation #CodeLearning
    #ProblemSolvingSkills
    ============================================================
    Github code - github.com/VarshaDas/Grind169...
    🔔 Subscribe: / @codewithease-byvarsha
    🗓️ 1:1 Consultation with Me: topmate.io/varshadas
    🔣 Linkedin: / varsha-das-se
    🎬 Share: • Longest Repeating Char...
    Other playlists in the channel that you can follow:
    ➡️ Multithreading Java Series - • Multithreading Java
    ➡️Core Java Interview Questions Series - • Core Java Interview Qu...
    ➡️ Recursion Primer Series - • Recursion Primer Series
    ➡️ String coding interview questions - • String interview quest...
    ➡️ Arrays Series - • Arrays Series
    ➡️Linked List Series - • Linked List Series
    ➡️ Sorting Primer Series - • Sorting primer series
    ➡️ Binary Search Series - • Binary Search Series
    ➡️2-D array Series - • 2d arrays series
    ➡️Coding Patterns Series - • Coding Patterns Series...
    ➡️Time And Space Complexity Series - • Time and Space Complexity
    =======================================================
    If you found this content useful and valuable, please show your support by clicking the LIKE button. Your feedback is essential to me and motivates me to continue producing high-quality content for aspiring engineers and professionals like you.
    If you have any questions or concerns, feel free to share them in the comments section below. Your input is valuable to me, and I will do my best to address your concerns.
    To stay updated on new videos and content, don't forget to click the bell symbol to receive notifications and subscribe to the channel. By subscribing, you'll never miss a video and stay ahead of the game in your career development journey.
    Follow us on:
    ➡️Twitter - / codeease
    ➡️LinkedIn - / code-with-ease
    ----------------------------------------------------------
    Created and Instructed by:
    Varsha Das
    Mid-senior Software Engineer, Content Curator of @Code With Ease - By Varsha
    ➡️ LinkedIn - / varsha-das-se
    ➡️ Quora - www.quora.com/profile/Varsha-...
    ➡️ Hashnode - varsha-das.hashnode.dev/
    ➡️ Medium - / varshadas21
    To support the initiatives of this channel you can:
    Buy Me A a Coffee - www.buymeacoffee.com/varshadas21
    Are you looking for an all-in-one resource to enhance your coding skills and prepare for coding interviews? Look no further than Code With Ease - By Varsha! Our channel is dedicated to making problem-solving in programming simpler and more accessible to everyone. We offer topic-specific videos on DSA preparation and coding interview topics, along with comprehensive "Primer Series" that teach various concepts and algorithms. With structured content and clear thought processes, our aim is to become your go-to source for all things DSA preparation and programming foundations.
    But that's not all! At Code With Ease - By Varsha, we believe that coding is about more than just landing a job or cracking the coding interview. Our ultimate goal is to create proficient problem-solvers who can tackle complex challenges and create amazing products. By learning to code with us, you'll not only prepare for interviews but also develop a long-term skill set that can be applied to various fields. Join our community of passionate learners today and start your journey towards becoming a proficient problem-solver with Code With Ease - By Varsha!
    #codewitheasebyvarsha #datastructures #codinginterviewprep

Komentáře • 17

  • @AbhishekKumar-dm6ss
    @AbhishekKumar-dm6ss Před 10 měsíci

    Great Explanation👏👍🏻👍🏻👌

  • @suhasdevang9332
    @suhasdevang9332 Před 9 měsíci +1

    awesome explanation ma'am, Great job

    • @codewithease-byvarsha
      @codewithease-byvarsha  Před 4 měsíci

      Thanks.
      You will be thrilled to know that, along with our regular content, you can now get something extra.
      As part of our CZcams 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 - czcams.com/channels/iWsQBA97JYGntWs99ZrQmw.htmljoin

  • @anulipidas8300
    @anulipidas8300 Před 11 měsíci

    👍👍👍👍good👍👍👍

  • @venkateshhs3776
    @venkateshhs3776 Před 6 měsíci

    Thank you.

    • @codewithease-byvarsha
      @codewithease-byvarsha  Před 4 měsíci

      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

  • @_akashchaudhary
    @_akashchaudhary Před 8 měsíci +1

    undercooked food served

  • @nikhilkumarjamwal5322
    @nikhilkumarjamwal5322 Před 10 měsíci

    for non-repeat
    why did we not use while loop?
    can you explain it?

    • @codewithease-byvarsha
      @codewithease-byvarsha  Před 10 měsíci

      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 Před 3 měsíci

      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 Před 8 měsíci +3

    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  Před 8 měsíci

      You are right, I agree, I could have used a better example for the dry-run. Thanks for your feedback!

  • @rishavkalra3843
    @rishavkalra3843 Před 6 měsíci

    thanks mam

    • @codewithease-byvarsha
      @codewithease-byvarsha  Před 4 měsíci

      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 Před dnem

    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.

  • @Venom-oy1wq
    @Venom-oy1wq Před 10 měsíci

    try to explain the code .......not so good

  • @ManishGupta-wb2wc
    @ManishGupta-wb2wc Před měsícem +1

    that was the worst explanation bro