Oddbean new post about | logout
 When it comes to nested loops, many developers assume that having a while loop inside a for loop automatically leads to O(N^2) time complexity. However, new research suggests that in certain cases, the combined complexity can remain O(N). This is because the number of iterations of the inner while loop can be independent of the outer for loop, or the total work done by the while loop across the for iterations can be bounded by N.

Source: https://dev.to/dleedev365/til-nested-forwhile-loops-can-have-on-time-complexity-in-some-cases-dsa-for-technical-interviews-18l2