Valid Palindrome II

Sdílet
Vložit
  • čas přidán 5. 07. 2024
  • For business inquiries email partnerships@k2.codes Discord: bit.ly/K2-discord
  • Věda a technologie

Komentáře • 77

  • @vcfirefox
    @vcfirefox Před 3 lety +11

    Dude. The number of leetocde solutions without explanations, but you took the time and effort to elaborate it out. You definitely deserve the best career possible. I am 10 years in the field and its rare to find people like you.

  • @TheElementFive
    @TheElementFive Před 2 lety +5

    Runtime is too strict, and edge cases are too annoying for this to be an "easy" problem.

  • @asherintech
    @asherintech Před 4 lety +3

    Awesome explanation, even without knowing Java you make these questions super easy to understand 🙏

  • @drteeth11
    @drteeth11 Před 5 lety +2

    Kevin, thanks for the great videos. I don't have Java experience, but I've been watching all your stuff because you explain in such an understandable way. You've surely been through hundreds of these problems, do you often run into a question that leaves you stumped for a bit? It would be interesting to see you code through a difficult problem for the first time.
    Question on prep vs. interview... when working through problems on LeetCode, I usually start small and keep iterating and executing/testing the code until i reach a satisfactory solution. Should the goal be to instead think through the problem and code the solution all in one go?

  • @jayakumarm8923
    @jayakumarm8923 Před rokem

    Awesome explanation man.....you are on next level 🔥🔥🔥🔥

  • @GustavoDiaz93
    @GustavoDiaz93 Před 3 lety +21

    Whenever you say "pretty simple problem" I feel bad because to me it´s really hard (even though leetcode says "easy") I need more practice.

  • @atift5465
    @atift5465 Před 5 lety

    Nice vid but im a bit confused, how does the helper method work for the inner 2 indexes? Wouldnt the indexes overlap and not not beyond the while loop?

  • @AmolGautam
    @AmolGautam Před 2 lety +1

    Thank you for such a nice explaination

  • @gokul5293
    @gokul5293 Před 5 lety +3

    I like the way you approach the problems.

  • @jeezradz
    @jeezradz Před 4 lety

    just perfect explanation. Thank you!

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 4 lety

      jeezradz thanks! If you like my explanations check out the interviewing service I launched thedailybyte.dev/

  • @jonscheifley6863
    @jonscheifley6863 Před 5 lety +1

    Great video. Keep up the good work!

  • @chandra375
    @chandra375 Před 4 lety

    Kevin .. thank you for all the wonderful videos.
    I was wondering if just keeping a counter on the first while loop would suffice and if the counter goes over 1 then you can return a false instead of creating another method for checking the substring for a palindrome

    • @lizdenhup
      @lizdenhup Před 4 lety +1

      I could be wrong but I don't think this would work; if there was a mismatch everything subsequent to the mismatch would also be a mismatch...because the 'non palindrome' character is essentially introducing a shift...

    • @amitadhikaree1801
      @amitadhikaree1801 Před 4 lety +1

      yes, i tried that approach. It didn't work. e.g "lcupuufxxfuupucul". Try checking your logic for this example.

  • @doumkatekz
    @doumkatekz Před 5 lety

    Excellent thank you

  • @AJ_708
    @AJ_708 Před 3 lety

    great work!

  • @lkoadil1
    @lkoadil1 Před 2 lety

    Kevin excellent explanation ..

  • @sandipbhaumik
    @sandipbhaumik Před 4 lety

    It runs, Awesome!!!

  • @madhuravp
    @madhuravp Před 3 lety

    very cool explanation! I was unnecessarily doing recursion in my helper function! This is better :)

  • @freefortravel4317
    @freefortravel4317 Před 4 lety

    I'm having trouble solving the problem 1172. Dinner Plate Stacks from Leetcode. I don't really understand the explanation in CTCI either. A video regarding this would be much appreciated. I've spent a fair bit of time with this problem. The methods I'm having trouble with are leftShift and specially join, if you check the CTCI implementation. Thanks!

  • @NishankSingla
    @NishankSingla Před 3 lety +3

    I don't think it is O(n) complexity. Looks like O(n^2) beacuse of nested while loops for the worst case. If the input string is already a valid palindrome then it will be O(n).
    If we don't make a isPalindrome function and put 2 while loops directly inside the top while loop then internal 2 while loops will be O(2n) and with outer while loop it will become O(n^2).
    Please correct me if this logic is wrong.

    • @theendurance
      @theendurance Před 2 lety +3

      wrong, it is guaranteed O(N) in the worst case. When we find a mismatch, we loop through the rest of the string twice (substring from i + 1 to j, and substring from i to j - 1). If the first and last characters are mismatched, those 2 isPalindrome calls will be O(2N), and we immediately return after they are called. We NEVER call isPalindrome more than 2 times, so its guaranteed to be an O(N) solution in the worst case.

  • @SolamanRaji
    @SolamanRaji Před 3 lety

    Thnx Kevin. This is helpful :)

  • @HornOKPlease
    @HornOKPlease Před 3 lety

    I love this question

  • @siddhantmisra5664
    @siddhantmisra5664 Před 5 lety +4

    I was recently asked the spiral matrix question in the first round of my Facebook interview. Somehow managed to implement it.

  • @47tejash
    @47tejash Před 3 lety

    When they give condition in the problem like Strings length is less than 50k chars etc. Do we need to explicitly add it in the code to check? Could you please explain.

  • @harigovind11
    @harigovind11 Před 3 lety +1

    I was asked this question in Facebook interview.

  • @TrollFreeInternet
    @TrollFreeInternet Před 5 lety +11

    Bro i know u probably have other important things to do but can u pls make more videos quickly?i love the way u explain and want to learn more from u..maybe make 2-3 videos a day? Xd

  • @nknidhi321
    @nknidhi321 Před 3 lety

    Thanks Kevin!!

  • @alanchavez16
    @alanchavez16 Před 5 lety

    Thanks for helping us with these coding interviews. I have to take a part 2 - Amazon Full-Time SDE Assessment by this Friday. Would you give me any advice before I take it?

    • @psn999100
      @psn999100 Před 5 lety +1

      Leetcode Amazon Card from Leetcode Explore section

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 5 lety +5

      Of course! My advice would be...
      1. stay calm! These questions can't be THAT hard if they're just a coding assessment so try to remember that when you're going through them!
      2. Read up on the most asked questions on LeetCode before taking it (hopefully you've been doing this :P)
      3. don't sweat it. What i mean by this is if it doesn't work out it's ok! There's tons of other incredible companies out there and you can always reapply. Remembering this tends to help me out.
      I hope these help and I'd love to hear how it goes tomorrow! Best of luck, you've got this!

    • @alanchavez16
      @alanchavez16 Před 5 lety

      @@KevinNaughtonJr Thank you so much I appreciate it! I will do my best!

    • @alanchavez16
      @alanchavez16 Před 5 lety

      @@psn999100 Thank you. I have been practicing in Leetcode that page is fantastic. I just barely graduated and I cant wait to learn more and more every time. Thanks for your help again I appreciate it.

    • @unknownman1
      @unknownman1 Před 3 lety

      @@alanchavez16 You got the job?

  • @amrholo4445
    @amrholo4445 Před 2 lety

    Thanks alot

  • @marksaunders8430
    @marksaunders8430 Před 3 lety

    Seems to be timing out for me, isn't it O(n^2) and not O(n) ?

  • @julietgeorge4858
    @julietgeorge4858 Před 4 lety

    yes to the music. lol

  • @vinayakumar2381
    @vinayakumar2381 Před 5 lety

    Cool Explanation

  • @MP-ny3ep
    @MP-ny3ep Před 2 lety

    You might wanna try using a whiteboard to explain stuff.

  • @divitvivit8803
    @divitvivit8803 Před 3 lety +1

    its failed for input s="cbbcc"

  • @darod6098
    @darod6098 Před 4 lety

    Thank you.

  • @antoniomartinez3429
    @antoniomartinez3429 Před 4 lety

    definitely a tricky one!

  • @monojit104
    @monojit104 Před 4 lety

    how can I check palindrome by removing at most 2/3 characters ?

    • @darod6098
      @darod6098 Před 4 lety

      having a counter and decrementing it instead of directly returning the result of isPalindrome should work

  • @ehsanhosseini5861
    @ehsanhosseini5861 Před 4 lety

    Is this solution recursion? I can see you return one method inside another method, what you call this process?

    • @danavram8437
      @danavram8437 Před 4 lety +2

      No. Recursion is when you keep calling the same function over and over again (building a stack of consecutive function calls), with a different state, until you get to a base case.

    • @mohamedamer5904
      @mohamedamer5904 Před 4 lety

      Yes it can be, because actually you are solving this by doing the same thing twice but for smaller range and you can limit the number of the recursion calls by counter, here is code for it by Swift:
      func validPalindrome(_ s: String) -> Bool {
      var low = 0
      var high = s.count-1
      return validPalindrome(s, low, high, 0)
      }
      func validPalindrome(_ s: String, _ low: Int, _ high: Int, _ count: Int) -> Bool {
      if count > 1 {
      return false
      }
      let sChars = Array(s)
      var low = low
      var high = high
      while low < high {
      if sChars[low] == sChars[high] {
      low += 1
      high -= 1
      } else {
      return validPalindrome(s, low+1, high, count+1) || validPalindrome(s, low, high-1, count+1)
      }
      }
      return true
      }

  • @uccanh2750
    @uccanh2750 Před 2 lety

    damn, i fell so stupid after watch this video ...

  • @bobij0
    @bobij0 Před 5 lety

    For the second func chars are not compared for initial input vals i,j but are incremented right away...why is that still working I wonder.
    P.S awesome videos

    • @algoseekee
      @algoseekee Před 5 lety +2

      That's how post increment expressions work, they actually change the values *after* the values are being read.

    • @algoseekee
      @algoseekee Před 5 lety

      For better understanding try to solve this little puzzle: let i = 3; i++ - i - ++i = ? (you may execute this expression manually from left to right and check yourself in a browser's console after). Enjoy! :-)

  • @alankardingshsingh3701

    Hey Kevin, Please upload the video for longest palindrom substring Leetcode and word search II Leetcode. Can you please do it by tomorrow? Also, word search II using Trie.

  • @kunalchoudha
    @kunalchoudha Před 5 lety +1

    Hey Kevin...just FYI, this question's moved to hard category now.

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 5 lety

      really? That's weird...I just checked again and it still says easy for me

    • @kunalchoudha
      @kunalchoudha Před 5 lety +1

      Kevin Naughton Jr. interestingly the question page shows it as easy... but if you search for it in search bar on home page, by typing 680...it says hard as difficulty level...😊

  • @symbol767
    @symbol767 Před 2 lety

    String problems are trash