Problem Solving Interview Q | JavaScript