Shortest Path Algorithm Leetcode Javascript Questions