System Design Problem Leetcode Javascript Question