Programming Interview Questions | Live Interview #4

An error so yeah that’s one of the bugs there’s another bug as well in line 18 I’m actually not appending the correct thing to the result but we can we can fix the partial of end portion first so just the easiest way.

Would be to just pop one element and pop two elements then pop three elements the alternative is if I were to do kind of like a negative one right because this is saying that I’m going to pend one.

String I can’t do that because this is a keep forgetting immutable strings in Python if I use the negative one it would say that I’m I’m adding just one character to the end of the last string I want to try.

It this way first and see if I can actually do that it’s like clutch equals yeah I want to say that this kind of works out of code but it just looks really messy if I do it like.

That sorry I can’t have people actually or because I maybe one way I can make this at least a little bit cleaner is if I do that but at least it’s the same everywhere just look at like first string if I have like you know X equal pay.

And I can do something like this now it’s X is AP and it’s being mutated but I can’t actually append I do that yeah that’s not a valid operation and I only.

I’m sorry so in Java there’s.

Something called string builder where you can append strings to it but I don’t know it’s such a similar thing exists in Python do you want me.

To check yeah well I can explain a what ends up happening here between line 28 in line 38 so basically all I’m saying is that my current octet is going to be inside of this list is that really required yeah I guess that’s a that’s an easy way to separate the.

Values right and then what I’m saying is in the last value and the last value inside of my partial.

Gonna first append one character then two characters then three characters and then I’m just going to remove that entire octet when I backtrack it does work out it’s just kind of messy and that the final value type that I’ll get it’s going to be a list partial is going to be something like this well let’s these are all gonna be strings and then it’s going to be what’s a 101 you know a non-word right instead of just having the strings directly.

Yeah because you can’t order the string yeah that’s not what ends up making a difference it’s more because I do this partial dot append and then when I do the plus equals on specific characters.

I you know just add to that existing inner array I’m struggling to think of how I can actually do this without using the inner array because I can’t just use plus equals every time yeah I need some separate way to you know well I don’t need to use the list the other option I have is to just you know put in the dot over here.

To do our partial dot and then I put in the entire substring and then add a dot that should still work out it’s roughly the same issue I want to say in terms of logic.

At least but it changes how I end up actually combining my final result to add to the result for my final partial so right I have some string here or some list that does perform its string this.

255 255 so I’m going to say that the solution should end up equaling to stop dot join on HB item of 0 for item in partial yeah right so that should fix up art where actually wasn’t appending the correct result right so back to going.

Through an actual test case of this now that we’ve reasoned through some of the larger bugs sorry I don’t know why this result is.

Highlighted I forget a parenthesis somewhere yeah I’m not sure why result on why nineteen is being highlighted as a syntax error the brace has closed correctly.

Hey what I’m still running the bottom I guess we’ll figure out when we run it but going through the actual test case I had this 255 255 1 111 and then 35 right.

Off the bat I’m going to say that I have nothing as the solution the partial is empty I have zero picks and I’m at the 0th index so cool my pick isn’t equal to zero and my length of partial is still equal to zero so I skip this check and what I say is.

I’m going to append a list and on to the final element there I’m going to add the item at the 0th index and now I’m going to.

Reverse so cool one of my items now is two and now I’ve rehearsed on the rest of the string so going through again my length of partial this time is nonzero so my current range is the last item I see I check if the value at the 0th index of the current range is equal to zero it isn’t and my current range isn’t greater than 255 so cool again I’ll end up backtracking and I’ll pick the.

Character which is now a five and this should end up repeating over and over again except it’ll end at four when my pick.

Is four and so now my to my octet Tsar two five five and two I check my end is not.

Equal to the length of s that means that I don’t have a solution I returned this backtracking should work out for all steps you know it’s yeah I definitely.

Couldn’t go through all of them because it’s you know it’s pretty expensive let’s say that yeah I picked the second item and I picked.

The third item like I said it would and then my when I have an octet value of say five this one pop operation should get rid of.

It so cool let’s pretend that I have a valid solution because I kind of reason about the partials not equal to.

Zero portion earlier what will I get here five five five all I’m doing is saying that the item of.

Zero for each of the items in partial is what I’m going to add and put a dot in between them so that should give me exactly what I want yeah and so this looks pretty okay to me if I run this with the actual test case I’m sorry that just cut out okay go ahead yeah go ahead and run to Prince Khalid I pees on five 11135 and there’s seems to be a.

Syntax error here I don’t know what that is but I guess I’ll find out in argument must be a string so this on line 26 oh right I forgot I converted this into a list so it should be naked the last item and the at the 0th index.

Ha okay there’s definitely strange pick 2.

5 5 1 ha we just print off what I’m actually getting as a partial value here to 5 5 to 5 I think my actual check between line 223 and line 89.

Actually didn’t find any valid solutions at all from this so it can’t be just as one this one section I.