u2i interview question

Reimplement piece of your code with different time complexity