Not Able To Solve Leetcode Javascript Interview