map it to its index which is gonna be four minus one that's three and we're gonna set the value at this position to be negative so it's now going to be negative NUMBER_TOKEN. next we're going to go to this index uh we have four so once again we're going to look at index NUMBER_TOKEN and set it to be negative but it's already negative so the operation that we're going to use when we actually code this up is just take the absolute value of this value and then set it to be a negative so we're gonna take the absolute value of negative four that's gonna be four then we're gonna set it to be negative four so that's an easy way to code it up that means we won't end up changing this uh okay so now we're at the last value we just visited this now we're here and we have a negative NUMBER_TOKEN. so we're going to map that to the index we're going to take negative NUMBER_TOKEN minus NUMBER_TOKEN and the index is going to be negative NUMBER_TOKEN. so clearly we ran into a problem because what we found out is in doing this we might be overwriting some values like over here we we wrote to this value uh but later we're going to end up visiting that value what happens if we visit a negative value well once again we're just going to take the absolute value of it because by changing each of these values to negative we're not really getting rid of any data we're just marking it to say that okay if the value at index NUMBER_TOKEN is negative that means NUMBER_TOKEN exists in our array if the value at index NUMBER_TOKEN is positive that means NUMBER_TOKEN does not exist in our array but the data itself is not changed this is going to be a NUMBER_TOKEN or it's going to be a negative NUMBER_TOKEN. so we can always take the absolute value of it so now we're done iterating through the array and like i said since this is negative and this is negative that means uh NUMBER_TOKEN plus NUMBER_TOKEN NUMBER_TOKEN and NUMBER_TOKEN plus NUMBER_TOKEN for these do exist in our input array which is of course true right we had a one and we had some fours uh but since the values at index one and two are positive that means one plus one which is two and two plus one which is NUMBER_TOKEN do not exist in this array so this is going to be our return value and that's exactly what we wanted to return in this case so i hope this kind of helps you understand why we don't need extra memory with that being said we can now 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 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 like i said in the drawing explanation we're going to have two phases of this algorithm uh we're going to mark the
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 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 END_SPONSOR_TOKEN