A knight on a chessboard always alternates colors with each move, meaning an even number of knight moves will always return the knight to the same color square as its starting position. This invariant property allows for efficient problem-solving by simply checking if the start and end positions have the same color parity (determined by whether the sum of their coordinates is even or odd).
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
3996. Even Number of Knight Moves (Leetcode Easy)
Added:Hey hey everybody. This is Larry. This is me going with Q1 of the weekly contest 511. Even number of night moves.
Hit the like button, hit subscribe button, join my discord. Let me know what you think about this one. So this one um let me first by saying that uh this is not an ad. All right. I I don't know. I this is not an ad. And you'll see what I mean soon because um actually earlier today I was just doing my Dolingo. I was, you know, doing uh I I I do I I I try I try to do Spanish, a little bit of Chinese, and a little bit of chess just because to mix it up, right? Uh and as luck as it would have it today, uh when I was doing the chess lesson, it was a lesson on knights. And one of the things that you notice about knights is that um for every move, the color changes every move, right? So it goes from black to right, right to black and so forth. And you can see it in here, right? And so in every two moves or even number of moves, it will be in the same color as it started. So that's kind of the core first idea. Um you can of course do a BFS and you see the entire graph or something because by by that principle um it will always be in the same parody, right? Meaning that that's the invariant. You cannot go from like there's no like if you're trying to go from cell A to cell B, there's no like there's a even path and an odd path, right? There's only one way. It's either even or odd because of the set things we said. It goes to black to white and white to black. Um, and that's it. And then the there's a there's a couple ways you can think about doing the color.
This is the way that I did it.
[laughter] >> [cough] >> Um, yeah, this is basically the XY coordinates. Uh, you add them in M 2. So that'll give you an idea of a color. It doesn't have to be black or white. I forget which one is which anyway. But for these problems, you just have to choose pick that they're the same color, right? And that's it.
Um, and kind of prove it to yourself.
The idea is that um, I mean, one idea, there are a lot of different ideas, right? is that you start at the 0 0 and if you go from 0 0 to 1 zero then this changes the parity by one and then you do right and then now you go up or you go down in this case one by one also changing the parity one by one so that's kind of the idea of course there's more to this and you can play around with it but that's it um so I was able to get this I mean I took it a minute because I was just laughing and kind of talking about the story that I just told you and you can watch the new uh the portion live I don't know I think today I'm just in a weird mood where I wasn't really solving it that fast. I was just like monologuing too much. But uh but yeah, but I recognized this immediately because I was doing my Dolingo. Again, not an ad. But this also kind of tells you, you know, how much experience matters, right? Or practice and stuff like this because I could have been practice a chess uh a chess problem and I would have gotten the same thing.
Anyway, that's it. That's all I have with this one. Let me know what you think. Thanks for watching and yeah, you can watch me sub live in the contest next but uh yeah um okay should not have been distracted but that's okay. All right, let's see. X by 8 by 8 true even number of moves return force. Um, so this is actually kind of funny, right? Because I actually just did something like this, right? Um, is that I actually was I thought I should just solve the problem first. I actually just did chess lingo dual lingo on chess and the lesson I was doing is that uh a horse actually always moves to a different color every time. So an even number of moves is the same color. So that means that that's basically the idea, but it's kind of wild, right? So yeah. So return start, right?
Uh it's kind of very uh quizendal, right? So that's basically it. Decided to have the opposite of it. I you know, but no, it should be the same color, right? So it's kind of cool. Uh uh I I mean it's an obvious observation but I just didn't think about it and I was doing Dualingo with chess. Uh and and that was literally the lesson. So it was very fresh in my mind. It's very funny.
Uh and I spent a lot of time talking about it instead of solving in like 10 seconds and show off. But uh but it is what it Thanks for watching everybody.
Hit the like button, hit the subscribe button, join me on Discord. Let me know what you think about today's prom, this contest, everything in between. Stay good, stay healthy to good mental health. I'll see yall later and take care.
Related Videos

TOP 15 Data compression Interview Questions and Answers 2019 Part-2 | Data compression | Wisdom jobs
wisdomjobs
281 views•2019-06-28

CTS 158: 802.11w Management Frame Protection
ClearToSend
4K views•2019-02-04

NDSS 2019 Send Hardest Problems My Way: Probabilistic Path Prioritization for Hybrid Fuzzing
NDSSSymposium
496 views•2019-04-02

How realistic is Cities: Skylines?
CityBeautiful
159K views•2019-02-14

GUIs & TUIs: Choosing a User Interface for Your Python Project | Real Python Podcast
realpython
2K views•2025-04-04

The OSI Model - Explained by Example
hnasr
225K views•2019-05-12

Cloud Computing - Introduction
elithecomputerguy
98K views•2019-10-07

From Traveler's Dilemma to Dynamic Routing | Demystifying Networking
IITBombayJuly
5K views•2019-08-04
Trending

WOW! Judge TURNS THE TABLES on Trump in His OWN $10B LAWSUIT!!!
MeidasTouch
197K views•2026-07-23

Playstation NO DISC/NO BUY Fight Is Over...
DavidJaffeGames
4K views•2026-07-23

Steam and Xbox Just Dropped The Hammer On PlayStation
OhNoItsAlexx
9K views•2026-07-23

Americans Confused in Australia for 17 Minutes Straight
IWrocker
17K views•2026-07-23