Sulopa Solutions Interview Question

they ask me to solve the problem on JavaScript