Toddle interview question

Solve an dsa question in js