The IP Address Decomposition Problem - Compute All Valid IP Addresses From Raw IP String

Поділитися
Вставка
  • Опубліковано 29 вер 2024

КОМЕНТАРІ • 113

  • @BackToBackSWE
    @BackToBackSWE  5 років тому +22

    Table Of Contents: (I'm literally screaming. I'm sorry I'm talking so loud/fast/aggressively. I messed this up for many of my first videos. This is a past version of me.)
    Problem Introduction 0:00 - 1:46
    Explaining The Approaches 1:46 - 6:07
    The Code 6:07 - 11:07
    Time & Space Complexity 11:07 - 12:47
    Wrap Up 12:47 - 13:25

    • @algorithmimplementer415
      @algorithmimplementer415 4 роки тому +2

      Question : Why is the space complexity constant? There must be O(n) call stacks for n length string, no? Please, please correct me if I am wrong.

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому +1

      IP address has a constant max length

    • @SudhanshuKumar-lp1nr
      @SudhanshuKumar-lp1nr 3 роки тому

      ​@@BackToBackSWE Similarly the time Complexity should also be constant? because the length of the IP address would be constant and the program would always take constant time to run.

    • @hk123y
      @hk123y 3 роки тому +1

      Can you please tell why you use path[segment] = -1 at last?

    • @SudhanshuKumar-lp1nr
      @SudhanshuKumar-lp1nr 3 роки тому

      @@hk123y Actually it's usually done for backtracking, which is of no use in this case.

  • @gourabchowdhury6456
    @gourabchowdhury6456 5 років тому +2

    wish you made these videos 3 years earlier .. this is priceless material for newbies. Take note .

  • @bhavyachawla7176
    @bhavyachawla7176 4 роки тому +2

    Really really appreciate the hard work that you put into each of your videos Man !! I have a request , can you please discuss the question 'Split Array With Same Average' (LC 805)

  • @AradhyaKasat
    @AradhyaKasat 4 роки тому +10

    Wow, I was struggling with backtracking till now, but this one video cleared so many concepts. Just did like 5 backtracking problems back to back after watching it. Thank you so much for such amazing content!

  • @lokeshs9449
    @lokeshs9449 4 роки тому +1

    your energy comes out of my desktop screen

  • @trantung2013
    @trantung2013 3 роки тому

    A minor mistake is that value could be between 0 and 255, not 1 and 255.

  • @anujsrivastav6444
    @anujsrivastav6444 3 роки тому

    why it's so simple but still confusing!!!

  • @SudhanshuKumar-lp1nr
    @SudhanshuKumar-lp1nr 3 роки тому +1

    Similarly the time Complexity should also be constant? because the length of the IP address would be constant and the program would always take constant time to run.

  • @xwa130
    @xwa130 5 років тому +5

    I like your videos. I watch full version of ads to support you. Haha! Also, could you please past links in the description/comment area for any materials you recommended in your video? That would be awesome!

  • @patil88ganesh
    @patil88ganesh 5 років тому +6

    One of the best solution this is! Thanks a lot!
    Is there a code available for this anywhere?

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      almost: github.com/bephrem1/backtobackswe/issues/1

  • @surajch2678
    @surajch2678 4 роки тому +5

    Very great explanation. I was looking for a way to remember these patterns. Keep doing more and more videos like this.

  • @see2672
    @see2672 2 роки тому +1

    Thanks for such a wonderful explaination

  • @abhinavnarang7855
    @abhinavnarang7855 4 роки тому +2

    Dude, I know you are the best. Please just don't shout at me. You do this in every video but still, you are the best with 3 keys.

  • @sarahzaman3173
    @sarahzaman3173 2 роки тому +1

    This made backtracking problems so much easier. Thank you. And it's okay you spoke loudly/aggressively. I think the passion adds emphasis to what you're teaching.
    Goodluck on your journey! I'm definitely subscribing.

  • @THEAVISTER
    @THEAVISTER 3 роки тому +3

    Wow, this is an amazing video! Thank you for explaining this so thoroughly! Love the enthusiasm too 👊🏽👊🏽

    • @BackToBackSWE
      @BackToBackSWE  3 роки тому +2

      thx

    • @SudhanshuKumar-lp1nr
      @SudhanshuKumar-lp1nr 3 роки тому

      Do you think the time Complexity should be constant? because the length of the IP address would be constant and the program would always take constant time to run.

  • @sammiewalker2860
    @sammiewalker2860 2 роки тому +1

    Love how enthusiastic you are, you don't find that with a lot of tutors. Preparing for a coding interview, thanks for the help!

  • @taksh8138
    @taksh8138 2 роки тому

    Sir if we use recursion not backtracking then the time complexity will remain same or it will be effected?????

  • @kaichenghu3826
    @kaichenghu3826 5 років тому +3

    man, your thinking process is gold

  • @heyitsnikhil7956
    @heyitsnikhil7956 5 років тому +2

    at each point we have maximum 3 choices.
    if we use base case: if(segment>4) return;
    the maximum height of tree will be 4.
    so, to be exact time complexity would be: O(3^4)
    am i right?

  • @nikkis8102
    @nikkis8102 6 місяців тому

    Thank you so much for your enthusiasm; it helps me to learn faster!

  • @shashankkumarshankar3655
    @shashankkumarshankar3655 5 років тому +1

    Your explaining is just crystal clear! I wasn't sure why solutions on LC were checking for end of input string in base case but you explained it clearly. And in my solution, I was validating the constrain in the base case. But, I think validating it before going down a path is lot efficient. Thanks for your hard work of explaining!

  • @janvisingla3746
    @janvisingla3746 4 роки тому +1

    You just killed it ,So much energy :) just loved it .I got the whole concept very clearly.
    Thanks

  • @meghaharlalka
    @meghaharlalka 5 років тому +2

    did u try running your code? Does it pass in leetcode? I couldnt get it to give me the right solution

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      hmm

    • @justinejose5111
      @justinejose5111 4 роки тому

      I had similar kind of logic, leetcode has got some crazy cases, which didn't even make sense for me.

    • @sandeepkumarnagamalla1020
      @sandeepkumarnagamalla1020 4 роки тому +1

      I got it working in Leetcode after making few modifications to the above code
      class Solution {
      public List restoreIpAddresses(String s) {
      if(s.length()

  • @sophiehall38
    @sophiehall38 5 років тому +2

    Nice solution! It would be very kind of you to talk a little slower. Thanks again

  • @gauravsalunke9900
    @gauravsalunke9900 4 роки тому +2

    This man spits GOLD

  • @dragoslavmilutinovic5731
    @dragoslavmilutinovic5731 5 років тому +1

    I think that it should not be break,but continue on if for constrains.
    Generally awesome video bro

  • @decostarkumar2562
    @decostarkumar2562 2 роки тому

    Time complexity is O(1) 🤔😦

  • @tathagatgawle2172
    @tathagatgawle2172 4 роки тому +1

    I like your Energy and teaching style, please make more videos.

  • @mrshubh101
    @mrshubh101 2 роки тому

    Wow! I've always struggled in implementing backtracking, but this video explains it best!

  • @yashadukia9646
    @yashadukia9646 4 роки тому +1

    Love the explanation. You just made the question so easy to code

  • @RizwanAhmed-pv1mg
    @RizwanAhmed-pv1mg 3 роки тому

    Please use pictorial diagram instead of just speaking.

  • @muralijagdev
    @muralijagdev 4 роки тому +1

    can you please share github link in the description

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому

      There is no code sample for this currently I think

  • @hizkiajuan
    @hizkiajuan 5 років тому +1

    Hi Ben, seems u forgot to explain the "unchoose" ("our choice") part.
    Could u please tell us more? (path[segment] = -1)

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      Ah, yeah, all we are doing there is "clearing" the segment when we backtrack away from the choice we made. I can go more in depth if you'd like but try imagining how the recursion would pan out.

    • @hizkiajuan
      @hizkiajuan 5 років тому +1

      Back To Back SWE Hmm.. so it is okay if we "clear" the segment by other value than -1, isn't it? But, since without "clearing" it still output the same answer, how is it then?

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +1

      It doesn't matter if you clear the path since the result is reaped ONLY when the recursion bottoms out. I should edit the code sample...I realized this a while back and forgot to edit it. You know what I mean though right? If I backtrack and keep making choices...the segment's value will get overwritten by any subsequent choices and the final result will be reaped only when we get down into the base case....then we backtrack...and keep going until the recursion finishes.

    • @hizkiajuan
      @hizkiajuan 5 років тому +1

      Back To Back SWE Yap.. I got it, Ben.. in all, thanks for being so helpful! Keep up the good work 👏🏻

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      @@hizkiajuan sure

  • @parteeksachdeva3039
    @parteeksachdeva3039 4 роки тому +1

    why should len>=2 in order to break plzz help

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому

      I don't remember the code but it has something to do with validation right? Validating a segment

    • @rieljunliguid4043
      @rieljunliguid4043 4 роки тому

      It's for checking if the current segment has leading 0, to make it clearer, python syntax:
      if int(segment) > 255 or (seg_len >= 2 and segment[0] == '0'):
      break

  • @abhinavghosh725
    @abhinavghosh725 3 роки тому

    just clarification :
    the line should be
    if(val>255 || len>1 && snap.charAt(0)=='0')
    return ;
    AND NOT
    if(val>255 || len>1 && s.charAt(0)=='0')
    return ;
    's' should be 'snap'

    • @BackToBackSWE
      @BackToBackSWE  3 роки тому

      ok cant verify replying fast to comments

  • @andrewghorbani5991
    @andrewghorbani5991 5 років тому +1

    Thank you for all your videos, they've been a great resource for me and I think I'm finally starting to get backtracking down!

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      That is pretty cool haha. I made all these backtracking vids while I was still getting the hang of making videos so they're rough...

    • @andrewghorbani5991
      @andrewghorbani5991 5 років тому +1

      @@BackToBackSWE Just want to say, I had my onsite interview with Google today and got a backtracking question! I followed and explained the approach you give and pretty sure that got me a few brownie points, so thank you for passing on your knowledge once again :)

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      @@andrewghorbani5991 fuego. go get em'

    • @andrewghorbani5991
      @andrewghorbani5991 3 роки тому +1

      @@BackToBackSWE 2 years later I find myself back here haha! Your vids are a gem my dude

  • @shikharchaudhary6984
    @shikharchaudhary6984 3 роки тому

    you saved me from Output Limit Exceeded

  • @emonitani
    @emonitani 4 роки тому +1

    great presentation, thank you my Brother

  • @ritikmishra3643
    @ritikmishra3643 3 роки тому

    Now you know how to solve backtracking problems and how to scratch your itch while making a youtube video...

  • @novadragonxx5
    @novadragonxx5 5 років тому +1

    you da man Ben

  • @amitranjan6998
    @amitranjan6998 5 років тому +1

    Can you please generate a tree and show how backtracking is working here .

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      Yeah, I'll run back in time and edit that in, brb 🏃🏃💨🏃🏃💨

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      WOOO! Ok back. But all jokes aside yeah I will try to make a video on calculating recursion trees for recursive algorithms (although you'd never do this in an interview).

    • @amitranjan6998
      @amitranjan6998 5 років тому +1

      @@BackToBackSWE Thanks alot , It's very helpful to everyone ,if you explains the code with the Recursion Tree ,So that everyone can visualise what's going on . Your video is really very helpful . Thanks mate :) :)

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      @@amitranjan6998 sure

  • @grzegorzgorkiewicz2918
    @grzegorzgorkiewicz2918 5 років тому +1

    What is meant here with the unchoose step? Why is it important?

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +1

      The unchoose step is so that we undo the state that we added ourselves to return to the previous condition we were in before we made a choice and recursed on it.

    • @grzegorzgorkiewicz2918
      @grzegorzgorkiewicz2918 5 років тому

      ​@@BackToBackSWE Thanks! Why doesn't "-1" appear among results, if you add it? I solved this problem with a list in place of your array: bit.ly/2weiKSZ, but it took a little bit guessing when it comes to the "unchoose" step. I wonder whether we can somehow eliminate the segment variable...

    • @viditmaniyar2846
      @viditmaniyar2846 5 років тому

      @@grzegorzgorkiewicz2918 Regarding choosing and un-choosing: In graph world, when you decide to do a DFS on a node (say X), you mark it as visited in case the traversal comes back to the same node, you know that you have visited it for this recursion stack and should not include it. Now when you are done exploring all the options, you come back from the recursion stack to the X node, you can move on to next node, say node Y and perform the same DFS exploration. But before that, you need to un-choose the node X since it will be a valid candidate for the new DFS exploration that starts at Y.
      Now apply the same thinking here for segments and see if it helps with the understanding?
      And you are correct, we can choose the remove the segment variable in the un-choosing portion all together. Instead we can do currentNumbers.remove(currentNumbers.size() - 1); and it will still work. All we need to do is remove the last segment that was added to the currentNumbers from the DFS exploration to make space for the next candidateInteger in its place for the same segment.
      Hope I did not confuse you and this helps.

  • @SudhanshuKumar-lp1nr
    @SudhanshuKumar-lp1nr 3 роки тому

    Love the Energy.

  • @БогданКостюк-н1ю
    @БогданКостюк-н1ю 4 роки тому +1

    Thanks

  • @mmfawzy4850
    @mmfawzy4850 4 роки тому +1

    Perfect

  • @bakhtiyardoskenov191
    @bakhtiyardoskenov191 3 роки тому

    Thank you! :)

  • @gordongao840
    @gordongao840 4 роки тому

    Overall, great explaination! But i am confused about one thing. when you to " res.add(path[0] +"."+path[1] +"."+path[2] +"."+path[3]);" isn't path[0] a int? and res is a list of string?

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому

      it is a string

    • @gordongao840
      @gordongao840 4 роки тому

      @@BackToBackSWE But path is a int[ ] as how you defined it.

    • @kalebs.gebrekirstos8041
      @kalebs.gebrekirstos8041 4 роки тому

      Good observation! However, when you concatenate the ints (path[0], path[1], ...) with the period ("."), they become strings. Do you see it now?