Larryโs real-time breakdown elegantly simplifies spatial manipulation into a concise two-pointer logic, capturing the essential intuition behind algorithmic efficiency. It is a pragmatic demonstration of how to bridge the gap between abstract problem statements and clean, performant code.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Daily Leetcode #2227: May 06, 2026 - 1861. Rotating the BoxAdded:
Yay, we did it. We are at the top of the mountain. But uh as you can see, and as uh as raindrops are getting on the camera.
Let me wipe this out a little bit. All right. Uh yeah, there's I don't know if this is the spot or like we're just high enough in elevation that, you know, this is where the clouds are at. Uh hopefully not or rather hopefully that's the case so that when I go back down a little we have some views to kind of take a look uh and not just because like a car just rolled in. I wish I took more photos when I was down there because I I don't know. It looked clear for like so long.
I don't know what happened here. Maybe it's just a spot. Hopefully. Can't even see anything. Anyway, uh yeah, hopefully it's just a spot. But uh for now I will chill and rest just for a little bit.
Yeah. So, I climbed that rock. There was a rock and I climbed it. And now, yeah, I cleared up a little bit. I mean, I don't know if it's going to stay this way, but at least it's cleared up a little bit for me to show you. So, I'm very excited. And I also have a better view. But I just want to, you know, this is me. I'm in it. But yeah, look at this. The uh what they call move on this side a little bit better. I don't know.
The Grand Canyon of Hong Kong or Tun, I don't know. Something like that. But uh it looks the the yeah it looks like a lot of just canyons and I guess that's what the name suggests. I don't know.
I'm not really creative. Uh it looks pretty cool and very hikable. But I it's supposed to or it should be hikable but um I hear that this is like the it's where it's the firing range where they practice shooting stuff. So you have to like get a permit or something to hike it or something. Uh which I don't have.
So I mean I'm not going to do it today anyway. And here is the the part of the town that [snorts] gives me uh yeah, you could say where I grew up kind of. So yeah, I spent a lot of time as a kid anyway. So yeah.
Yes. Patient wins.
[music] [music] Heat. Heat. N. [music] [music] [music] >> [music] [music] >> Hey hey hey, this is Larry. Day six of the day challenge. Hit the like button and subscribe button. Join in Discord.
Let me know what you think about today's vlog. I clicked on the link, I swear.
Okay, maybe I didn't. Uh yeah, I'm still here in Hong Kong. As you can see, I climbed a mountain today. Uh it's been a very hard day. It's been a very tiring day. So, I am just going to pass out.
And when I wake up, hopefully this uh link will uh wanted to load because um you know, people always ask me what's the first step of solving, you know, a legal problem. What should you do? What should you work on? I mean, the first thing that should happen is the prom should load.
Oh, there we go. All right.
Uh, yeah. And today we have rotating the box. We'll see how long this loads this time. Is it my Wi-Fi? Is it the code? I don't know. But it is not going.
Where are you going?
Nowhere.
I did I No, I clicked I clicked [laughter] on it again. So now it'll load twice as fast. That's how that works, right? Uh yeah. I hope everyone know Hope everyone's doing okay. My I was going to just say that my car is doing a little better, but but my foot is itchy.
My body is doing better though. uh in terms of like you know how when you know you you feel weakness in the sense that like you know like sometimes the wind blows it a little bit and you like just feeling it. Uh today I'm not I'm like probably back to like 90% but I'm still tired you know like I think my uh like things don't hurt that doesn't mean that I'm still not I'm not still recovering.
So yeah uh what I would like to recover is this farm though. Okay, this thing is still okay. At least we did the problem.
Today we have 1861.
Rotating the box. You give it a a thingy and then when you rotate them then uh you play Tetris or something, right? Or you just drop. Uh this is going to be very annoying, but should be okay. It's only a medium. H. Okay. I mean, yeah, I guess the first thing you do is just the rotation, right? That probably makes sense. Um, and then you just simulate the gravity. I don't think um I don't think concept I don't think conceptually is uh uh uh uh anything that tricky but um or algorithmically there's nothing too tricky about algorithm, right? The only thing you have to uh um be careful about of course is that you don't do these rocks one move at a time because then it just becomes like an n square thing, right?
Because if each move each rock force n times or some o of n times then it's going to be like you know n square for each one and then this just becomes too big because n is 500 right. Um so that's the only thing but you can do that like by just fast drop or something right uh and we'll point out what that means when when I get closer. Also when I come mountain I got bitten by a lot of mosquitoes. So um so I'm going to scratch myself a little bit. Yeah. Uh let's let's let's uh let's start the implementationish.
Um maybe it's just the way I'm sitting that could say I feel like I've been coughing less but maybe the way I'm sitting I'm putting pressure on my throat and as a result I'm coughing a little or my uh my foot's a little itchy which makes me want to cough a little bit more. So maybe let me sit up actual straight instead of being lazy or feeling lazy which I am but you know I don't have to feel it and plug in my power laptop.
Okay, there you go. All right. So um okay.
Um yeah. So now maybe we have like a new box. I'll just put box is equal to uh just say none for now. Times uh uh rotator right. So right something like this and then for I the original box. So we'll just create the box first right there was a ji.
So um 0 0 goes to z goes to 0 n. So um the new so okay box grid 0 or i j let's say is equal to n minus j minus one i. Is that it?
Oh, no, no, no. I think it's this one.
Could be wrong. Been confused a lot. I just print it out, too. So then, yeah, of course, this is before the gravity takes place, right?
Of course, I guess it is my fault. My computer or my my Wi-Fi is lagging. So, uh, uh, some this is what should be a simple thing. It's taking a while.
I keep unplugging my power.
I need to use longer cable also. Why?
Why? What are you uh lead code, Larry?
Wi-Fi, whatever it is, please. I just press the button.
Uh, okay. Well, let's just pretend it works for now and then we'll uh Usually I do want to verify it, but uh Okay. So then now, let's say we rotate it the correct way. Um now we want to drop them, right?
Oh man. Unknown network error. Yes, thanks. Um, so now instead of um, you know, like I said, you could take the lowest piece and then you keep on going down, right? And so forth, but you don't want to do that. You want to just do a um like a skip like a two pointers algorithm, right? So you go to the last available space that you could put a thing and then you keep on moving the other one. Uh, and then you just it teleport them and shift them up by one kind of thing, right? So that's go. And there a couple of states of course. Oh man. So I can't I don't even know if I could submit at this point. What are you doing computer? Um but yeah uh I mean there's a there are more consideration because of the star right the the um the impossible blocks or whatever the obstacle um but um but uh yeah uh so that's that's kind of the idea. But then another thing to note of course which maybe is obvious is that because you're only forming vertically each column is an individual thing. So if you if it helps you, you should think about it that way. So that when you do um when you try to come up test cases, you don't have to come up with the entire board. You just have to come up with one columns test case um to kind of you know figure out where to put them, right? So um yeah. So maybe we say so we just do for I don't know I or let's say C in range of C right oh there we go I don't know why we end but uh that's good that's good that's good right so this is right was that a miracle or that was that just cuz that came by really fast and then now it's not again is just me though my other internet is fine let me ask someone like is Leo's having some issues or something. I don't know. So, my internet is I mean, okay, not gonna lie, right? My internet is slow, but it hits everything like pretty instantly. So, I think maybe Leo was just having some issue and it came back like very quickly for half a second, right? I guess. Oh, here you go. Uh, okay.
C is on the Did I do this wrong? Maybe I did. Actually, I think I did do this one because I just wrote this one usually as I do naturally, but this is why I like to do it uh test things block by block, right? Um and here, yeah, it looks okay, right? I mean, obviously, we didn't drop it yet. But I just want to make sure that, you know, this is the pre-drop. It would look okay, right? So, okay. So, now we have that part done. So, we for each column we want to solve. And then maybe we do set bottom is equal to the last row, which in this case is actually R minus one, right?
Um and then yeah and then we have so so bottom is the free space and then so the idea that I you could in visualize is actually not just dropping it one at a time from the bottomless pepple or whatever this is rock whatever box.
All right. Um uh yeah uh so then yeah so then now we go here and what what I want why I want to say that is because it may look a little bit confusing um in that what we want to do is actually consider the board having no uh what's this called? Boxes, rocks, whatever. None of them, right? And that way when you insert them or like in this case where the bottom one is already there, you could rethink it of or you could visualize it as uh putting it the bottom pepper at the bottom box. So something like that. All right. Um uh so we want to start from the bottom.
So something like this, right?
Uh don't want to use I let's just use Whoa, let's just actually use cough.
Uh okay. So then now um Okay.
And there are some like nuances with that, right? Because if the bottom is not free, then we um then we can increment, right? or well tenic is decrement because we move it up but you know hopefully you know what knew what I meant. So you would write something like box of okay so well you check first right here if box of row of uh yeah column uh if this is equal to um a period then nothing happens right because we don't drop it here else if box of row of column is equal to um uh what's the walk or whatever this is the drop right then now we set um box of row of car is equal to box of row of column I guess in this oh no no no uh and now we set bottom is equal to this I guess there's another way to do it just by counting things but um and then regrouping them I guess that could work too actually. But maybe the way that I'm doing now is fine for now.
And then else it's an obstacle. What happens when you have an obstacle? Well, in both case still nothing to be honest, right? In the sense that okay, now we we moved um we dropped rows of car into here or we skip right.
Uh then now we check if box of row of bottom is equal to this or actually I guess if if this is in um this or this then bottom we subtract one. So then we move up right. I think that should be good.
Um the only thing that I actually No no no it's not. Um what's else is the thing? So then now box of row of bottom well we don't drop it but we set bottom is you go to um the current row. So then now in this case it'll go up to the next one for the next one uh to loop. I think something like this. Um hopefully this is right. Let's just give it yolo some run. Um did I do this wrong?
>> [cough] >> Oh, I uh I confused. I mean, yeah. Uh RNC is all the original thing. So, this new is not um eh. Okay, fine. Maybe we just re I mean, I think the more cleaner way is to kind of separate them out.
But, uh Okay, it's too right. Uh oh. Oh.
Uh is it a No. Why is it not range? The bottom can be Oh. Oh. Oh. This is uh Oh, why did I do this? This is so That's so dumb.
How did that happen?
Uh, okay. Is that the only time? No, there's another use.
Why would I Why did I don't know? Maybe I think I'm just, you know, used to doing Oh, I have to replace this, don't I? H. Okay. So, I mean, I think we did the dropping part. Okay. It seems like, but I do not or like I I removed it from the original H.
Uh, if this is a rock then, oh, I guess maybe I could just write something like this.
Uh, maybe that'll work.
Oh, okay. There you go. Uh, I don't know why I didn't think of that one, though.
It's kind of silly to miss a case like that, but uh, okay. Let's uh yolo submit.
Okay, good. Um yeah, this is gonna be linear time, linear space, right? I mean, this is linear on both and this is linear also on both in time and space.
And remember, uh linear in this case is all time C because we look at each element once uh input element. And so yeah, uh that's it. That's all I have for this one. Uh hope this is okay. Right. Let me This is just rotation and this is just sliding down. It's a lot of dead time in this video because of all the internet being weird. Or maybe I think Leo's being weird to be honest, but maybe it's better now. I don't know. Good enough for me to submit. Did I already submit?
I mean, good enough then. Yeah. Uh, so that's it. That's all I have for this one. Let me know what you think. Thanks for watching. Stay good. Stay healthy to good mental health. I'll see y'all later. Take care. Bye-bye.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 viewsโข2026-05-28
How agent o11y differs from traditional o11y โ Phil Hetzel, Braintrust
aiDotEngineer
450 viewsโข2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation๐ฏโ
LearnwithSahera
1K viewsโข2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 viewsโข2026-05-29
Search Algorithms Explained in 60 Seconds! ๐ค๐จ
samarthtuliofficial
218 viewsโข2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 viewsโข2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 viewsโข2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 viewsโข2026-06-01











