Programming Interview Questions | Live Interview #4

Only going down four sacks max so really I guess it is no matter what kind of like constant time yeah just the representation of the code makes it look you know exponential it’s cool I think that does end up being okay as a solution there’s some optimization.

I could make in the sense that I know that there’s absolutely no way I can pick one item if it turns out I.

Have you know like three three three twelve fourteen digits left like there’s no way right it has to be.

Three digits that I pick there but that sounds as the naive approach I don’t think I should really have to do that is it okay if I go ahead with the recursive approach that I talked about sure yes salad ip’s right just because I can’t actually work with string consults I’m just going to convert it into.

A list let’s start off then I could have a result array and I should be able to make a partial which is going to be called include all of the numbers in the current set of calls so sees an inner function so I’m just using nested functions.

Just so that I can like instead of.

Passing the values I can refer to the resultant parcel array in the in the you know larger scope so all I’m going to be doing.

Is saying that I have some directed valid IPS which keeps track of which index I’m currently picking at in the string as well as how many pics.

I’ve made so far so right off the bat i am at the 0th index and i’ve made 0 pics so what i want to say before i make the base case is that I either append of the partial like my partial solution one character two characters or three characters so I append.

S from n to n plus one and then this is one recursive fault otherwise I.

Pick two characters or otherwise I pick three characters so I can just kind of copy and paste this and make more immersive calls more option is to actually just.

Pop off the values every time but because I know that it’s the same value so I can just how long is this true yeah I should just be able to add along and I think it’s only in.

The final section that I’ll have to pop three times but I’ll have to do partial dot pops say three times in here right so just again summarizing what I did I decided to add the first character and see what happens if you know that’s my pick otherwise I add two characters and I see what happens if that’s my pick otherwise I pick three characters and see what happens.

If that’s not there in the base case I end up having that my pick is just equal to four.

Which means that I’ve added you know four items so if X equal to four and I find that my.

End has you know picked all sell them as possible and look what I would have is I found a solution wait oh my partial I never return if I found on my engine.

Sure if I don’t pass by reference or pass by volume it’s the same.

As Java where it’s passed by assignment so do you think it will carry the same number that you are sending from the previous stack oh so when I’m using the numbers those are just going to be you know the numbers I pass down right so pick.

Is directly from the directed value ip’s function argument so it carrying the legend it doesn’t remember that I’m sending the only confusing part would be the partial thing because I have these nested.

Functions it’s just following like.

Normal lexical scope and it’s it’s going to.

The previous block so this partial on line 18 ends up referring to the same partial is line 12 cool so right that is my base case there’s also the cases of actually handling whether I have a valid IP so the easiest way I can think of to do that.

Is to just check whether the number that I have is within the range of 0 to 255 but there’s a problem with that in the sense that if I have 0 and I have 2 to that obviously doesn’t make you know any sense.

At all and that could end up happening if I just called if I add the next three elements and I make a recursive call and just check if my integer is you know within 0 to 255 I want to say that this is a edge case that I should be able to handle by just checking first that these your index isn’t 0 and then doing the second check of.

0 to 255 because any other place that 0 is then it’s fine like I can do a 2 0 2 or 2 0 0 those are still valid let’s say if when partial not equal to 0 what.

We want to do is translate that idea if a partial of reduce it would be negative 1 0 is equal to 0 mmm tens of zero is it easier if I store everything as strings or integers I’m gonna say it’s probably easier if I just keep.

Everything as strings yeah and we return otherwise the other cases that hits and partial.

Negative one is equal to let me just assign this to make the seat here right so one case without saying the current range the 0th.

Index is equal to 0 then return otherwise it’s that I have a current range is greater than equal to zero range I want the opposite of this sorry mixing this up it should be that if it’s a I mean I can’t ever have less than zero right so I guess the only case that’ll have to check is that it’s a less the value is.

Greater than 255 so that should be the real invalid case yeah because it’s impossible for me to.

Get negative values here right oh this is a typo cool I want to say that this should end up being pretty much the translation of the idea into the correct recursive calls but it’s really helpful to go through an example here or even before that.

So right so my list of s ah there’s an R so yeah so I was just saying what if you’re wrong range is like one zero zero four do you think it’ll cover the.

Case what if the length is greater than zero like 1 0 0 then the integer value of that will be greater than to define your return comment ok what do you mean 1:04 just in case you have them in your passion in your parent range of the.

Number of digits that morning right okay so there definitely was a place that I messed up on this and this is how this is the part where I was appending to the partials so I said earlier that I could just append to the partials the individual.

Items but that is not true because initially I was supposed to have say values like 255 255 inside the partial and.

Internally I would build up the to 5 and then 5 but instead what I’m doing is to 5 min 5 which is a which is.