Two Pointer Leetcode Problems Javascript