Reading a constraint backwards means knowing the largest n a complexity can afford. Write largestAffordableN(complexity, budget): return the largest integer n >= 1 whose cost is at most budget operations, or 0 if even n = 1 costs more. budget defaults to 1e8.
The cost functions, written the way you would count steps:
'O(n)': n'O(n log n)': n * Math.log2(n)'O(n^2)': n * n and 'O(n^3)': n * n * n'O(2^n)': 2 ** n, 'O(n*2^n)': n * 2 ** n, 'O(n^2*2^n)': n * n * 2 ** n'O(3^n)': 3 ** n and 'O(n!)': n!
Every cost grows with n, and n can be as large as 100 million, so do not try every n one by one.