Top Array Problems Leetcode Javascript Solution