Modern computers do about 108 simple operations per second.
Rule of thumb for 1-second limit:
- O(n): n≤108
- O(nlogn): n≤107
- O(n2): n≤104
- O(n3): n≤500
- O(2n): n≤25
- O(n!): n≤10
Example: If n=20 and you need O(2n), that's ≈106 operations. Should pass in well under a second.
Always check constraints first. If brute force fits, use it. Simple code has fewer bugs.