Alright guys, we're gonna go over then the the recent coding challenge 653 division 3 today And I'm gonna explain what I did to actually solve this for these two problems The first one I got ace. I got it wrong the first time Then I got a seed the second time because of division by zero I Think some something like that now There's a specific test case that caused me to not get it right anyway Here's the problem required remainder. So you have x y and n Which is three three integers and you need to find the maximum k which is between zero and n Such that k mod x is equal to y Okay, and then the mod is just like the remainder operator by the way, okay? In other words, you're given x y and n you need to find the maximum possible integer from zero to n That has a remainder y mod x, okay? All right, so this problem isn't actually that hard I'll explain what I did and then I hope you guys could understand it. All right guys, so Basically This is the problem given x y and n we need to find a k that is between zero and n such that K mod x is equal to y Okay, so how do you do this problem? well, first of all we could let's try to represent k in terms of x and y because If we we know we're given x y and n and if we could find a way to represent k in terms of x and y Then we could probably solve this problem, right? so However, how do I represent k in terms of x and y? So first of all, let's just Think about how the mod operator works again. So let's say I take seven mod by three And what is that so if I go three I try to divide seven by three right and then I figure out Oh, it's two three times two six seven by six one. I would get one Right a remainder of one because seven mod three is a remainder one So then how would I represent seven mod three three? How would I represent three and one in terms of seven? Right, it's simple. Just look at how you did your division earlier, right? Seven divided by three was gonna give you some number Okay, and that's some number you multiply by three add by your remainder. You'll get seven, right? So in this case seven divided by three gave us a Value of two and that that number was two two times three gave you six six plus one is seven Right, so seven is equal to three times two plus one right So in terms of modulus Basically, I'm dividing some number by another number and get that number if I multiply them again and add by the remainder I'll get back to my original number So how do I represent k in terms of x and y? Right because if I represent k in terms of x and y and we're given x and y we're gonna be able to solve for k So first of all K mod by x is equal to y. We know that right so k mod by x is equal to y So if I want to represent k in terms of x and y Right, I would have to do this It's gonna be the same thing as how we did it here What we have to do is there's some number when you divide K by x and let's just call that q right q is gonna be some number like q is it gonna equal to some number Any number whatever it is right right and then q multiplied by x Plus y is gonna give us k right q multiplied by x plus y is gonna give us k Right because q is some quotient. It's some number when you divide by x by k by x So that's why that's how we got this k is equal to x q plus y. Okay So now our issue is that okay? We have We have a x and y but we still have two variables, right? We don't know what q is We don't know what k is right so and now we have to try to represent k in terms of N and y right because we know that k is between 0 and n right k is between 0 and n So if we could represent k in terms of n Then we could figure out how to do this right So since k is between 0 and n Let's think let's say I have a number line One and ten right a number line one to ten Let's say my number is at this point Six so this is my number right I Tell you that this number is between one and ten right well. How would I get to this number six? Simple I would have to subtract starting from either one or ten From ten after subtract some number from my upper bound of ten by some amount In order to get to my number six so in this case I would have to subtract four from the upper upper bound ten to get me six or I could add Some amount of number from one so in this case plus five to get me to six So it's the same case in here K is between zero and n right so let's draw a number line of right here Zero and n and K is at this at this point zero and n right if I want to get to my number k How would I do it? Well, I have to add k from zero, but I don't know what k is Do you guys get it? I don't know what k is Right, so if k if I don't know what k is my only bet is to subtract some number from n to get to k So in this case, let's just call it w right if I subtract some number w From n I would get to k. So let's write that so Instead of instead of writing k. I'm gonna subtract n K is going to equal to n minus w where w is some distance from n Okay, so now you have n minus w. So now let's just plug n minus w into k into this equation Right so using substitution. So I'm gonna have n minus w is equal to x q plus y Okay, so now we have this Now we have this whole issue right here. Okay, and q plus We have n minus w is equal to x q plus y Okay, so now we now we know what this this side is Let's just rearrange it. Okay, we're gonna rearrange this So now I'm gonna have let's add w on the right side on both sides and subtract y from both sides So we're gonna have n minus y is going to equal to x q plus w Okay, so now at this point you should realize that You could actually get the number that you want well now since we have n and y We're good because we're given n and y if you have this side right and then all you have to do literally is just Divide by x Right using this equation this equation here and this equation here we could find we actually could find what q and w are now Right because the definition of modulus is if and division is that if you mod by something you You divide by that number and then you could you get the remainder Right, so now I could get I could get at my w now Right because if all I have to do is just take n minus y divide Have this number n minus y mod by x Now give me w right The reason why this give me w is because like X is some number that we're multiplying by q right and if you take n minus y and you mod by x That means you're dividing by x Right you divide by x and you get the remainder the remainder is going to be w Right based on the definition of modulus of what we saw here. So because if you have n minus y if you now divide you mod by x You're gonna get w Because n minus y and you divide by you yeah if you divide n minus y by x You're going to get some number Right, and then it's remainder is going to be w because we know n minus y is equal to x q plus w So that gives us this equation w is equal to n minus y mod by x Right, so now you have this this number now. We could just plug in all our numbers From here x y and n to get our w Once we have our w all we have to do is plug it back in here and then solve for q right, so if Once I have w I'm gonna plug this back in here and then solve for q and to solve for q I would just have to do n minus y minus my w then divide by x would give me q right um, but Yeah, and then once that occurs we could just do You guys just do Yeah You can solve for q and then after with it you solve for q you could also solve for k because now we know what k is k Is equal to n minus w? Right, so once you have your w you just plug it back into here and you can solve for your k So yeah, that's basically how I did this problem. So I'll show you guys the code now alright guys So this is the code just read in t number test cases read in Wild t minus minus read an x y and n and then the w remember w is just n minus y Mod by x so that gives us our w. How far it is from n Once we have that number We're gonna subtract that number from n and then yeah, that'll be your answer What I also did was I also checked if it's less than zero if it's less than zero then what you should do is add By n and the reason why you add by n is because that'll bring you back to the boundaries between zero and n Right if you if it's less than zero. So yeah, if I so what I did was if n minus w is less than zero I just add by n add another n to the right side to bring us back to the original boundaries But I don't even think they test this honestly. Yeah Otherwise, I just do print out n minus w right and minus w is how far we were from And so yeah, that's how you do this problem. Ray come subscribe. I'll check you guys later. Peace


It's DDK and I got something to say. Today we had a $100 disaster from beginning to end. I'm talking about absolutely terrible.  Shout out to those who hated, baby. We'd like to be great in skating. Now, we do have a load to pick up from the carry company.  So 64 miles altogether for $100. I'm probably gonna go ahead and find my collar. But the question is this, why don't you do a load for $100? It's 64 miles, that don't make sense. Look, this is my plan, right? So I was planning on going to 7-1 anyway. From my house to 7-1 is about 40 miles total. So I'm like, if I'm gonna go to 7-1 for 40 miles for free to possibly get an order, why don't I just add an extra 24 miles and make $100 on there? Comment below and let me know if they're all smart or not. But it absolutely was smart. You guys are gonna see what happened. We ain't rapping, we ain't capping, we snapping. Let's go. It's like that, we are here at the pickup. It's time for us to go on here and run it up. This one ain't even open. Dang, she gonna receive an 07. I gotta wait till 7. What time is it? Honestly, nobody in this joint either. What's that, the ugly? Oh, it ain't open till 7.  Sheesh. So I just saw somebody go on this door. So I think it may be open now, but I don't know if they loaned anybody to 7. How you doing, boss? I have a loan to pick up. I have a loan to pick up to go to Chicago. Us company. Oh, it says Greenwood, this Greenwood? Yeah, the whole building is Greenwood. Oh, so this is what it says on here. That don't say it is, it's used or nothing. No, because the whole building is Greenwood. Oh, the entire building. Yeah, but over there, they got some freesty big size and right here, it's used. Oh, it's used here? And over there, it's fixed. Yeah, so I'm picking up juice. Juice? Yeah. So I'm just here, but you gotta wait till 7. Wait till 7? Yeah, okay. All right, appreciate you, boss. And just like that, I'm back, back, Mr. Magic City. I'm back, baby. I think I see somebody's ready to get up steady. Oh, Jarvan, check me in right here. A few moments later. How you doing, sir? I have a load to pick up to go to Chicago. I have to reach out, so I'll just come back in. They ain't giving me nothing. They just told me to print this paper and come here. Yes, come here. So I'm proud of it. There's no order number, no sales number. How do I question though, what's the future? Is it this? No. So you need a PO number or a order number? Order number. It starts in 2023 or 2024. Okay. And it ends in C-R-O-C-R-O. 2023 or 2024, it ends in C-R-O-C-R-O. All right, appreciate it. Back in for the third time. They gave me a confirmation number. I don't know if that's gonna work. We're gonna find out. What's going on with your boss? I don't know if that's gonna work or not. We're gonna see. I have a quick question for you. So they sent me this confirmation number. It's kind of a appointment confirmation. Is that it? Bro, that's not the number, but I can find your order number there. Tell them they need to find it up. Purchase order number. This is an appointment number. Sorry. This is an appointment number. They need to find a purchase order number. Purchase order number. P-O-N-O. What's your name? Jerome. J-E-R-O-M-E? I'm in the van.  I said you all. Guess what? It has been an hour and 50 minutes. And we still ain't got it in there, baby. They bought us all the produce to this door. So Q's out to my guy to help us sell it in there. But man, it's been critical, critical, baby. Like I got me right. I'm gonna go to the office. All right, thank you. This should right here sign right there. I know you've been doing this. Tell me about it. Can you sign this one? What? Bro, what are you talking about, man? Oh, I'm tweaking, I'm tweaking, I'm tweaking, see? It's been a long morning, my fault. You have a good ball.  Hopefully we can get in there like a bank robbery because it's critical, shipping and receiving. How you doing? I have a lot to jump off for you guys. A few moments later. I don't have anything with this. You don't? I don't have anything for this. It's 25, this is 2500, right? Yeah. Okay. I don't know, maybe I'll reach out to the dispatcher. All right, thank you. We back again. Let's see if this help us. How you doing, boss? All right, what's up? See if this help us. I don't know if it is or not. Okay, I'm back to bother you again. Does this seal number or this photo help with all? It was the same they pick up. I just picked it up from Melrose and I just came straight here. I took that picture from off the actual break. Okay, so you need a PO number. Okay, so I need the PO number from a dispatcher. I need the PO number from a dispatcher. Yeah, because I have this one but it doesn't pop up. That's not popping up. Yeah. Okay, so you need a new PO number. Yeah. Okay. Well, if that's the one dispatcher was, then yes. Okay. All right, thank you. And we are back again, clap again. Woohoo, we've been in here so many times. Let's see if we can get right this time. Okay, they told me to tell you it's for Albanese, which is right over here. Okay, it still ain't coming up, huh? This is critical. A few moments later. Uh-huh, an email? Yeah, because we don't have appointment for this. Okay. The location of the email, I'll just take it. Okay, all right, thank you. And I'm back for the 15,000 time. Hopefully they got this joint situated. They're supposed to reach out to him so we're gonna see. The dispatcher said the thing reached out to you guys. Yeah, he did, yeah. Okay. I can still get him right now. Okay. Question for you, so it's on the pallet. Do you guys unload it or will I have to unload it myself? Do you have a seal? A what? Do you have a seal? I don't know if that is. Oh. You do. I think it would be us. Okay. Do you need to go to town? I'll go to town. Stay back up halfway and then just wait for them until they come. Okay. All right. What's going on with you, boss? Am I supposed to unload this? It's like six buckets. It's just a pallet, it's a pallet. Let me show it to you. And look, if y'all don't want to, I just gotta reach out to the dispatcher and let them know so they can pay me for it for me to unload it. Otherwise, you can do it, whatever you want to do. It's up to y'all. Yeah, that's fine. All right. A few moments later. I don't know what it is. Okay, I'll let them know. Give me, that's your number that you should call me from. Okay, I'm gonna call you right when they say I'm ready. I'm gonna keep your call. Okay. Yeah, cause I gotta let them know first so that I can make sure I get paid. Cause if they don't confirm it and I do it, I ain't gonna get paid for it. So that's the reason why.  We finally got to unload this joint. Time to get on the plane. Pull over this $100 disaster.  I was highly, I'm ready about this whole situation. I'm just gonna ask you guys this. For those of you who use carrier companies or do over the road and all that stuff, how do y'all deal with all this nonsense? I don't understand it, man. I don't like sitting around playing games, waiting and all this stuff. It really, really bothers me a lot. I don't really like to do it, but you gotta do what you gotta do so you can get this money like it ain't funny. Now, I'm gonna tell you guys this. First off, the first mess up was they told us to be there at 6 a.m. I got up early. Well, I could have ordered early every day, but I'm rushing. I usually call my business partner at around 5.20. We talk on the phone, look on the road map and see what's going on. Which one you gonna pick? We gonna pick this, this, this, this, okay. And then see if we got them then go from there. I actually had to leave out of the house at 5 to get to the pickup location at 6. We get there at 6, the thing is closed. So after a while, like probably like 10 minutes later, I see a couple of people going in there. I'm like, okay, let me try to go in here and see if we try to get busy right quick. I'm trying to get in and get out because we're gonna run into Chicago traffic as you guys saw. Y'all saw the traffic, the traffic, traffic, looking for my traffic. I saw it come before marriage, it was critical. So the dude tell me that they cannot load me until 7 o'clock. I'm like, okay, cool, man, dang. So then I go back in there around 7. First off, people that got in line and cutting me now at this time because 7 o'clock, people that went there a little bit ahead of 7. So two people was in front of me before that. So boom, I do that, boom. Go in there, talk to them. Now they tell me I need a PO number. I'm like, come on, G. They told me, look, they did not tell me about no PO number. The dispatcher never told me about no PO number. They told me to print the paperwork and take it to y'all. That's it. Send me off with that. I had to talk to reach out to the dispatcher, finally got the info, went back in and I still didn't have a PO number. I had some number, I had some type of number. I can't remember what number it was but I did have a certain number and it was able to find the load, right? Okay, cool. Get loading everything. Now, the total time we waited at the pickup location all together was two hours and 13 minutes. We waited two hours and 13 minutes at the pickup location. So, okay, cool. After I get loaded, now I gotta go back in again and get the paperwork signed. I wanna get my stuff signed right here so I can go. I already been sitting here for 3,000 years already. So I'm trying to get busy but I can't even get busy. It's their process, so it is what it is. I don't own the company, so I gotta do what they say to do. Go in there, get the stuff signed, give me a get on the road, right? So, get to the drop off location. You guys saw what happened. I get there. Now, they need a number. The number that I got on the paperwork is not the right paperwork. I don't know if it's not the right paperwork but it's not the right number that they need to type in a computer to find a load and I'm supposed to be dropping off because, again, it probably was the P.O. number. So, I reach out to the dispatcher, wait a long, long time. They don't know what's going on. They have to reach out to the customer and the customer say, oh, okay, try this. I tried that. They told me to tell them some name or something. I tried that. That didn't work. So, after a while, another girl helped the girl that was helping me and then she's like, yeah, let me go check in the back and see what's going on. She went in the back. She said, unfortunately, we can't do nothing right now but reach out to the dispatcher and tell them to email us and I will let you leave the stuff here and you can go out there and you can keep on doing what you're doing. So, I'm like, okay, cool. She'll shout to her for looking me up. If you watching this video, she'll shout to you because you can help me out because I'll probably still be sitting there right now. So, boom, that happened. Finally, we got everything situated. Then, let me say this. Let me be very clear. I specifically text them and told them, hey, not only does the paperwork knock me since, I also might have to unload here. I told them this beforehand. I told them this like maybe an hour before we had to unload it. I told them this beforehand because when I saw the fans coming in, all of the fans, they had to unload right there. Where I was just at, they were like, no, they was like on number, I was on number 10. It was probably on like number three or four. We can see them right there. Every time a fan come in, they gotta get loaded from the dock right there. I specifically told them that. They told me they sent the information to the customer.  So now I gotta wait again for the dispatcher to reach out to the customer to get confirmed and then we had to unload that joint. Now, for that unloader, we did receive the extra $75. We don't say that. So we had 175 right there. But the wait time that we had to wait, extra drop-off location was two hours and 20 minutes. So all together, we waited four hours and 33 minutes of wait time and we could not go out there and get on the ground. We sat there and did nothing. So I reached out to them like, and I was supposed to be, they sent me to a race sheet. They're like, okay, so I sent the race sheet. The race sheet said it was supposed to be for 175. I reached out to them like, and I'm supposed to be compensated for the wait time. What about the wait time? Come to find out. Now, I think they're low key finesse. I really don't know for sure, but I think in the previous pass, I think in the past that they paid me after the first two hours, after two hours at the wait time, anything after that, you gotta wait. They also automatically pay you. But this time they tell us, that ain't how I work. We only supposed to pay you after two hours at the pickup location and after two hours at the drop-off location. So you could wait a total of four hours and not get paid nothing, which is absolutely crazy. So we got a measly $33 for four hours at some of waiting time. That's all we got. So for that one order, we only received- I thought it was $20 for 33 minutes. Oh yeah. Oh, my partner was right. I'm wrong. It wasn't $33. It was 33 minutes, I extra 33 minutes. So it was four hours and 33 minutes and we only received $20, not $33. We only received $20. Now, I know a lot of y'all out there, y'all always get it on the gig apps. The gig apps, they taking you up top. The gig apps doing this. Look, if I was waiting for the gig apps, I only got paid. Pull up and let's play. Let's add it up right now. If we did this on the gig app, and we did this on Disbatch specifically, not any other app, Disbatch. Disbatch pays you 75 cent per minute after the first 15 minutes. So let's take away the pickup and drop off, right? So let's take away, we're gonna take away that 30 minutes right there. So we just gonna leave it at four hours. 75 cent times, 240 minutes. If we really got an extra $180 for waiting there and I got $20. So that's all I wanna say about that. But for that order, we only received $195. And it took us literally five hours altogether for me leaving my house to get in there to do all that waiting time, to do all this stuff. And if we didn't have to unload, it really would have been critical. If that round one blocked off, oh, we would only got $120 for four hours. So unloading helped us with the $75, but it added a little bit more wait time. But I'm cool with that because we was already there for 3,000 years. It was absolutely terrible. Come up below and let me know what you guys think about this. I was angry, I was highly upset about this. Man, look, that's all I'm gonna say. But we do got another order, but the guard here didn't get an order. Order number two, y'all know my flow, sicker than the flow, I thought y'all knew. So let me tell y'all, let me go a little bit more just. I'm gonna do some little talking in this video. Now, let me say this, we were headed home, right? After this long time of waiting and doing nothing, sitting there, twirling our thumbs, we gonna go home, right? But then freight reached out to me and said they have an order to pick up from this place and then go to the, from a certain city and then go to the airport. So I'm like, I don't know. They say, are you available? I'll say, yeah, I'm available. Give me the details. They say it's from Atasca to Chicago, which is the, they want us to go to the airport. So I'm like, what's the payout? They're like, hold on, I'm in the meeting and all that. So I ain't got time to wait for y'all. But on our way doing that, this order did pop up, but I wanted it up and get these bucks. We have an order on, roti, roti, roti with a dabber wrench. We have a roti order. The pickup location is Home Depot. We're gonna drive three miles and we will receive a payment of $44.85. But the pull up to pick up the prize and drive. Let's go. And just like that, we are here at Home Depot so we can stack these chips like Pringles basically. Hey, how are you doing, sir? I'm gonna have a roti order to pick up. All righty, what's the order number? WJ47983013. That's what I'm talking about, nice and easy. Thank you very much. You have a great day, sir. This order is nice and sweet. I'm sorry, I ain't even gonna strap them down. That's what I'm talking about. They can eat it for me, they can eat it, eat it, eat it. We got to get them bitches that we gon'. It's time for us to go out here and get it on. Let's get it. And we are here at the drop-off. Let's see if the customer here so we can get busy real quick. I don't know if that doorbell work. I'm not gonna do it. They got the red dough. That's what I'm talking about. Yeah, that red dough. Y'all know my favorite color, red. I'm not trying to get this bird yet. Hello, how you doing, sir? I'm here with your Home Depot order.  Oh, okay, right here. All right, thank you. Knock this out right quick, so we can get this greased. Leave it back like that, Joe. It's not to risk that clean with it. Oh, what y'all know? What y'all know about that? What y'all know about that? Grease has that door gonna fall anyway, so. While I play games, we can do our thing. Let's change. Yitty! Six, comment below and let me know. Comment below and let me know. Don't forget your neck. At the garage. They're back under the floor, y'all know. Just like that, we go. Just like that is the end of the video. I hope you guys enjoyed the content. I'm gonna tell you right now, I absolutely did not enjoy making it. I'm gonna say this.   But then I'm like, it's already bad. Let's just make it even worse. Let's just go, look, sometimes you gotta fight through the bad times, baby. It ain't gonna be good all the time, especially when you're using these carry companies and doing these loads and over the road and all that stuff. All that sitting around waiting and stuff. I do not like it.  Because the way I think time is money. So if I'm wasting time sitting there, especially if I ain't making no money, I gotta wait full hour. I don't even wanna talk about it no more. Look, it is what it is, man. That's what happened. You guys were there. It was absolutely terrible, but we did make $239.85 enough money to pay the rent right around my pants, no 10. I hope you guys enjoyed this video.  I will see you guys on the next one. We going, we going, we flowing. You already know it, it's DDK and I'm on my way.