AKUNA CAPITAL interview question

Does the approach give the optimal time complexity?