Google Interview Question

Algorithm, time complexity of code