I had my 1st onsite round yesterday and this was the problem :
part1)
you are given an infine size chess board, (coordnates vary from -inf to +inf), and a knight intially at a given start point.
You need to tell minimum number of moves required for a knight to reach at a given end point.
(NO further constraints were provided even after asking)
soln : simple bfs, take map<point, moves> to keep the track of points taken and number of moves required to reach here , as you can't define any grid here.
part 2) you have also given a list of blocked points where knight can't go.
soln I told :
while considering the neighbour points in the above soln, jut add one more condition, if that neighbour belongs to block points or not.
TWIST : This is will not work, think about a case where your endpoint is surrounded by block points from all sides, making knight imposiible to reach at end point.
here, since the grid is infinite, you will be aways keep adding new neighbours into your queue, and you will never be able to come out of that loop. there will be no uppercase of grid size to stop it.
I was unable to think about this condition: to know when to stop searching further and consider that its imposible to reach at end point.
Let me know if anyone knows about this.
Thanks in Advance!