Programming Interview Questions | Live Interview #4

Oh hello hello hi hey how’s it going good how are you pretty good a little background about yourself sure so I guess I’m sorry I’m getting a bit of feedback from the mic don’t hear myself speaking oh I don’t know if that’s okay that seems to be fix yeah I don’t think I get your resolved so I guess.
Just some only a little bit I guess the background is.

I’m a student studying computer science at the University.

Of Toronto I did a couple of other internships previously and right now I’m just looking at a new grad roles you’ve used this maximum before yeah I.

Did a couple of interviews on here what’s your preference for language I’ll go with some Python for interviews I’ll just switch that over right now I’ll just paste the question here and we can start true so we need to find the longest substring any right okay so I.

Guess um going straight into that can I assume that these are all ASCII characters okay for the actual solution I don’t.

Think I’m going to work with.

That constraint what I’m thinking is I can let’s say I use these two separate pointers in order to determine what some window of candidates might be so let’s say I have a set which is going to be filled with the items that are inside of my window so I’ll have a window that’s initially set that both the start and end point are going.

To be at the 0th index and I’ll have a set initialize to the empty set I want to eating and moving forward my end pointer until I find a new character that is already within my set and this is with the you know portion of every single time that I am adding items or I am moving my end pointer forward.

I’m gonna add items into the set so my substring or my length of my substring is dependent on the distance between my or yeah the distance between my end and start pointer and once I have you know lost this sort of like invariant.

And I’m I want to keep that the set or that start and end only has unique characters I keep on moving up the backward pointer until it’s you know.

Met again right then my set has all unique characters or the window has all unique characters because the set of course as all Union characters complexity for this sir.

We’re going to say something sorry what if you find a cat what if your end pointer and count encounters the character that’s already in your set great so yeah so I was saying there in that case I move up the backward pointer right so that I keep on advancing forward and I remove items from the set until.
I find that this character the one that the end pointer is no longer in.

Set oh yeah sure so complexity for this ever seeing a big event its linear time we’re.

Ahead of the length of the inventory and that’s pretty clear because we’re just you know iterating through the array once right and the space complexity is a confidence because we’re.

Using these two pointers and nothing else I want to say that this should be pretty optimal.

Is it okay if I go ahead and cut this out yeah and we said our stars end-organ ability to zero zero right so let’s think about what the outer loop.

Would actually end up being would we want to have a continuing until end it’s the length of s I don’t think so I.