Shortest Path Problem Leetcode Two Pointer