Rapido Interview Question

The code has to be executable, we should explain time and space complexity