Basic Algorithms For Leetcode Javascript Question