Two Pointer Problems Interviewbit Javascript