Not Able To Solve Leetcode Javascript Solution