AKUNA CAPITAL Interview Question

Does the approach give the optimal time complexity?