Status: Rejected
Position: SDE1 at Groww
Location: Begaluru, Karnataka, India
I have already answered the first one with the optimal approach, but I was having some problems finding the optimal approach for the second one. She gave some hints in between, and I was able to come up with an optimal approach for the second one also.
Question: I was asked to make an application that would take the input of two people playing chess. The main task was to validate the moves that every player makes. The code was supposed to be modular, have correct logging statements, be executable, and return a particular error for any invalid conditions.
There were multiple doubts that were cleared in the questions, like what will be the initial chess positions and how the moves are played, and what moves will be given to play at a time. It was hard to make the moves as well, like if a player gives a move like Qxd4, first I have to validate if the player who wants to play has a queen on the board or not, and then I have to see if there is any player in between its route and I have to see if it can move to d4 or not, and I also have to insure that there is a piece on d4 as well. I also have to take into consideration if the piece can move up or not, because if you consider a pawn, it will only be able to move in an up direction for white and a down direction for black. So these things depend on the player as well. It was way too complex for a one-and-a-half-hour long question.
I was only able to validate the moves for 2 pieces by the end of time. I was able to make the application modular and have proper logging statements and exceptions, but my code was not executable by then. At the end, he told me to mail him the whole code. I am sure that even if I have given multiple machine coding rounds, I won't be able to complete it in one and a half hour.