Programming Interview Questions | Live Interview #4

Think we’d want to have it block starts near Weston blank of that just because you may have the condition.

That the longest is actually let’s say if we have like a a a and then a B I don’t know if this is.

End will end up hitting the actual.

End of the array before start will so our longest you know substring is going to be that final a B right so we want to make sure that start goes far enough right so this is one of s and I’ll see.

If I need to do negative one afterwards all right so let’s translate.

What I said I would do earlier first part is I want to check the current element and see if it’s in the set or whatever that end is if it’s in the set if it isn’t then I add it and move forward so say if if I’m in round nine pounds we’re gonna pound out add and just assign these as variables.

And now my sound and we add it and then we move up by one otherwise we want to keep on you know moving up the forward character eight until you don’t have that the NFL isn’t found so there’s also.

Supposed to be a check for longest a massive longest – and – start and otherwise we do sound remove starts out yeah equals one so I think that covers most of it I think it’ll probably be helpful to.

Run through a test case because I’m pretty sure there’s one more branch in here so probably useful to go through an example to.

Figure out that is or just maybe reason through it so let’s say I have the input you gave ABC so I’ll start off with both of the values start and.

End being zero I’m going to ah yeah okay so this will this should definitely have an out of bounds is one thing so right off the bat I want to check what’s called if my n.

Val is actually less than for my end is less than line of s yeah it doesn’t work out because I set my n valve earlier to being s end so I actually have to use FN anyways and less than Len s and whoops I just butchered this just the like if summarize what I did I can’t actually assign the value because I said earlier.

That I may keep on advancing the backward pointer but not the forward pointer right because the forward pointer may already be past the end of the array so this was just an out-of-bounds error fix but continuing what I have is right I’d start off I’d see that a is not in the set so I’ll add a and.

Then I’ll end by one and now my longest is one next time through I will see that B is not in and so not in found so I’ll add B and then.

Move up by one now my longest is two next time through ICC is not in so I’ll add it move up by one cool now I encounter a as my and Val and an val is less than s but s is s isn’t found so I’ll hit the ND case.

So what I end up saying is that.

I’m going to remove the a and I’m going to move my start up by one so okay now my start is at index one and my end is at index two or my end is at index 3 next time through my end val is still the same but now I see that I can add the a so.

Now my longest is BC a so for the general case I think these cases work out the thing I want to check though is the situation in which I actually go all the way to the end of the.