Amazon Interview Question

time complexity of ur approach how u approach this problem