Coding Interview: King And Queen On A Chessboard - Whiteboard Wednesday

  Рет қаралды 16,612

Irfan Baqui

Irfan Baqui

6 жыл бұрын

Check out the detailed data structures and algorithms course at www.interviewaccelerator.com
Welcome to Whiteboard Wednesday where I do software engineering interview problems on the whiteboard in a real interview setting.
Today's problem is on how to navigate on a 2D matrix in form of a chessboard.
Leave a comment on what problem you want us to cover next!

Пікірлер: 31
@michaelluong7387
@michaelluong7387 6 жыл бұрын
An alternative way to solving the diagonal case is to find the slope by computing (y2-y1)/(x2-x1). If that is equal to 1, then return True.
@JayPatel12928
@JayPatel12928 5 жыл бұрын
(Or -1) True !
@anujchoudhary3126
@anujchoudhary3126 2 жыл бұрын
Thank you so much man. More than this video your comment saved by A** today. Thanks a lot
@stewartzayat7526
@stewartzayat7526 6 жыл бұрын
This was a nice and fun problem! I hope I will get a question like this on my interview.
@franciskisiara
@franciskisiara 3 жыл бұрын
The biggest assumption here is that the interviewee knows how to play chess.
@hahafender
@hahafender 6 жыл бұрын
Awesome videos man! Thank you!!
@aaroncontreras2653
@aaroncontreras2653 4 жыл бұрын
Shouldn't the validate function check for && and not || since all conditions need to be met for a valid coordinate?
@stephanbranczyk8306
@stephanbranczyk8306 3 жыл бұрын
Good catch
@rafaelcupello2549
@rafaelcupello2549 6 жыл бұрын
Thanks!!!! Very good!!!!
@IrfanBaqui
@IrfanBaqui 6 жыл бұрын
Glad you liked it!
@EmulatE42
@EmulatE42 6 жыл бұрын
For diagonal just substract x1 x2 and y1 y2, and see if two result are same. Also maybe use abs just to be sure xD
@EmulatE42
@EmulatE42 6 жыл бұрын
Oh nevermind
@hymnsoftheheart
@hymnsoftheheart 6 жыл бұрын
Seems like there's an assumption here about the coordinate system in use here that should have been clarified. The diagonal case would have been easy (equal deltas) if the origin of the coordinate system is in the lower left corner.
@stephanbranczyk8306
@stephanbranczyk8306 3 жыл бұрын
The origin of the coordinate system threw me off too, but it doesn't actually change the nature of the solution. The queen can attack on either diagonal. And the king does not have to be at a higher elevation than the queen, for instance, he could below the queen on one of her diagonals. In the end, the placement of the origin doesn't really matter.
@sojuthomas7727
@sojuthomas7727 6 жыл бұрын
hi Irfan for diagonal checking,how about incrementing both x and y coordinate by one unit and repeat the step until matching coordinate found. is that completely cool..??
@DiapaYY
@DiapaYY 6 жыл бұрын
that is slower but would work if you did it in all directions.
@MahmoudAtef
@MahmoudAtef 6 жыл бұрын
Simply you can say tan(45) = 1 which means |kx-qx| / |ky-qy| ==1 and that's it
@eric325
@eric325 6 жыл бұрын
The slope formula m = delta y / delta x would have been been helpful. In order for the queen to be able to attack the king diagonally, m must be 1.
@DiapaYY
@DiapaYY 6 жыл бұрын
You'd need floating point though blah
@FistroMan
@FistroMan 6 жыл бұрын
Diagonal: Qx - Kx == Qy -Ky The order.. im not sure, does not matter
@kunalfarmah43
@kunalfarmah43 5 жыл бұрын
we could just use the logic of safe positions in the n-queen problem
@gyulanyirfalvi7013
@gyulanyirfalvi7013 6 жыл бұрын
at the end of the video your validation goes like this: If EL is integer OR (???) EL >= 1 OR EL
@IrfanBaqui
@IrfanBaqui 6 жыл бұрын
gyula nyirfalvi you're right, good catch.
@augustusmb
@augustusmb 6 жыл бұрын
Yes
@JayPatel12928
@JayPatel12928 5 жыл бұрын
No you're not, that is exactly when I paused the vid.
@siddharthmanumusic
@siddharthmanumusic 4 жыл бұрын
why not just proceed one block x and one block y, in each of the 4 diagonal directions. It's so easy
@abhisheksable622
@abhisheksable622 4 жыл бұрын
which company asks this question 😂
@stefano8936
@stefano8936 6 жыл бұрын
mm mh
1❤️
00:17
Nonomen ノノメン
Рет қаралды 8 МЛН
ИРИНА КАЙРАТОВНА - АЙДАХАР (БЕКА) [MV]
02:51
ГОСТ ENTERTAINMENT
Рет қаралды 9 МЛН
Получилось у Вики?😂 #хабибка
00:14
ХАБИБ
Рет қаралды 6 МЛН
Amazon Coding Interview Question - Recursive Staircase Problem
20:01
Every Chess Tip Explained In 10 Minutes
9:42
Chess Thugs
Рет қаралды 37 М.
URL shortener system design | tinyurl system design | bitly system design
34:39
Tech Dummies Narendra L
Рет қаралды 454 М.
Largest Square of 1's in A Matrix (Dynamic Programming)
20:43
Irfan Baqui
Рет қаралды 142 М.
Facebook Interview: K Most Frequent Elements - Whiteboard Thursday
14:24
Find the intersection between arrays: Coding Interview Question
11:26
Best Chess Game Ever Played: Forgotten Masterpiece
14:44
Chess Wisdom
Рет қаралды 7 М.
Best mobile of all time💥🗿 [Troll Face]
0:24
Special SHNTY 2.0
Рет қаралды 1,9 МЛН
Simple maintenance. #leddisplay #ledscreen #ledwall #ledmodule #ledinstallation
0:19
LED Screen Factory-EagerLED
Рет қаралды 15 МЛН
iPhone 16 с инновационным аккумулятором
0:45
ÉЖИ АКСЁНОВ
Рет қаралды 1,4 МЛН
Choose a phone for your mom
0:20
ChooseGift
Рет қаралды 1,9 МЛН