this video is brought to you by educativeio check out the link in the description where you will be able to save NUMBER_TOKEN on your educative io subscription stick around in the video to learn more hey everyone welcome back and let's write some more neat code today so today let's solve the problem reverse integer even though this is marked as an easy question i would say that this is definitely more of a medium question and that's probably why this question has so many different uh so many dislikes but i don't think it's actually a bad problem it's definitely good when it comes to bit manipulation so we're given a signed NUMBER_TOKEN-bit integer x the fact that it's NUMBER_TOKEN-bit is very important here we want to return this integer x with all of its digits being reversed and the only catch here is if reversing this integer x causes the value to go outside of the NUMBER_TOKEN-bit integer range which is this then and then we basically want to return zero if that's the case because we're working with NUMBER_TOKEN-bit integers if the integer overflows then we want to return zero and this is the portion that's actually going to make the the problem difficult because we are working with NUMBER_TOKEN-bit integers and we cannot assume that we can store NUMBER_TOKEN-bit integers or anything greater than NUMBER_TOKEN-bits that's what makes this question difficult i think because if we just take a look at the standard procedure that we would do take the first example over here we have one two three did you know we can chop off this one's place digit pretty easily you can do that by modding this by NUMBER_TOKEN. if we mod by NUMBER_TOKEN we're basically dividing this by NUMBER_TOKEN except we're getting the remainder which is exactly what we want that's how you get the ones place if i took NUMBER_TOKEN divided it by NUMBER_TOKEN what would be the remainder it would be three of course right so then we can get three so with this digit we want to create a new integer right so we're gonna start our new integer just being three right this is the result that we're returning it's going to be three let me you know write it down over here three right then another operation we can do on NUMBER_TOKEN now that we've processed this one's place we don't really care about the ones place anymore right we don't care about this three now we want to look at the next digit right so how can we basically chop this digit off well it's pretty easy you basically take NUMBER_TOKEN divide it by NUMBER_TOKEN when i say divide we're not doing decimal division we're doing integer division so when you do integer division we round towards zeros if we divide this by NUMBER_TOKEN we will get NUMBER_TOKEN because we're rounding down we're rounding towards zero so now we have NUMBER_TOKEN. we're going to basically repeat that exact same step that we just did over here basically now we're going to take NUMBER_TOKEN mod it by NUMBER_TOKEN and now we're gonna get the ones place which is two right that's the digit we were looking for so now we want to take this two and add it over here right now how can we do that well we have a d we have a value three so let's take three multiply it by NUMBER_TOKEN what do we get we get NUMBER_TOKEN right why did we multiply it by NUMBER_TOKEN because we wanted to shift this NUMBER_TOKEN
START_SPONSOR_TOKEN this video is brought to you by educativeio check out the link in the description where you will be able to save NUMBER_TOKEN on your educative io subscription stick around in the video to learn more END_SPONSOR_TOKEN