pretty much n plus m the size of both lists added together uh no extra memory complexity right so the memory complexity is big of one with that said let's finally jump into the code before we continue let me tell you a little bit about educative io educated io is a platform with hundreds of varied courses and these courses are comprehensive this python coding interview course has everything you need from data structures algorithms complexity analysis recursion dynamic programming object oriented design system design and even concurrency basics and yes that's all in one course you're not a python person don't worry about it because we've got you covered with similar coding interview courses for java c plus javascript and even more check out the link in the description educative dot io slash neat code to save NUMBER_TOKEN on your subscription okay so now let's code it up and i'm gonna make it look pretty easy but there are a lot of ways that we can go wrong with this so initially i'm gonna have lNUMBER_TOKEN and lNUMBER_TOKEN and just set it to the beginning of each of the lists and we're going to continue to increment them while both of them are not equal to each other and when they are equal to each other this loop is going to exit and what are we going to return well since they're both equal we could return either one we could return lNUMBER_TOKEN or lNUMBER_TOKEN i'm just going to do lNUMBER_TOKEN when they are equal what does that mean that means they intersected right they reached the exact same node but it could also mean that we reached the end of both lists right both of them happen to be null and we didn't find a result so in that case the loop would also exit and we would return null the easy thing we're going to do is of course set lNUMBER_TOKEN to be the next node and lNUMBER_TOKEN is also going to be the next node but what about when they reach the end of each of the respective lists what do we want to do then if lNUMBER_TOKEN was already null what would we do well in that case we're going to set it to lNUMBER_TOKEN so this is going to be only if lNUMBER_TOKEN is non-null else we're going to set it to be lNUMBER_TOKEN but not lNUMBER_TOKEN we want it to actually be the beginning of lNUMBER_TOKEN right which is head b lNUMBER_TOKEN is a pointer that we're currently manipulating we don't want to set it to lNUMBER_TOKEN we want to set it to head be the beginning of that list and similarly with this one if lNUMBER_TOKEN else if it is null then we want to set it to the opposite list which is head a in this case now let's run the code to make sure that it works and as you can see on the left yes it does and it's pretty efficient so i really hope that this was helpful if it was please like and subscribe it really supports the channel a lot consider checking out my patreon where you can further support the channel and hopefully i'll see you pretty soon thanks for watching
START_SPONSOR_TOKEN before we continue let me tell you a little bit about educative io educated io is a platform with hundreds of varied courses and these courses are comprehensive this python coding interview course has everything you need from data structures algorithms complexity analysis recursion dynamic programming object oriented design system design and even concurrency basics and yes that's all in one course you're not a python person don't worry about it because we've got you covered with similar coding interview courses for java c plus javascript and even more check out the link in the description educative dot io slash neat code to save NUMBER_TOKEN on your subscription okay so now let's END_SPONSOR_TOKEN