The naive BFS solution could be deducted yet the improvement is hard. Here is my solution on github: https://github.com/JSerZANP/leetCode_... Hi I'm a JavaScript engineer who is not good at algorithms, and currently practicing leetCode online. If you are interested, maybe we can learn together.