is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
Unless I'm misunderstanding this problem, the algorithm part is way simpler than most of these answers are making it out to be. As long as the board is empty, bishops moves are trivial. Simply rotate the chessboard 45 degrees in your mind, so that the corners are oriented horizontally & vertically. Next, decompose the board into two subboards, one made up of white squares & the other of black ones, since a bishop can only move on one subset.
- patrissimo July 03, 2013We now have two diamond-shaped boards, each containing 32 squares in the format (row length ordered top to bottom) 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, where our bishops move either side to side or up and down, just like rooks. The question is now equivalent to asking how a rook can move from one location to another in the fewest moves, which is simple - would you ever use Djikstra or any graph to move a rook? If not, you shouldn't use it to move a bishop, the problems are isomorphic under this transformation.
If the "rooks" are on different boards, there is no path. If they are on the same board, then if they are on the same row or column, it is a single move. If they are not, then there are 2 options: move up/down then left/right or vice versa.
This algorithm is very fast, but the direct translation into code is not particularly short, due to the transformations into and out of "bishop coordinates", and there are plenty of gotchas on the math. I'm not claiming this is the simplest solution to code, but it establishes that the answer is always either "impossible", 0, 1, or 2 moves; and gives you direct calculations for which the answer is, and what the moves are (if any).