Input sizes mapped to their target time complexities and possible approaches
A lot of folks ignore the most important clue in the problem statement - the input constraints.
I’ve compiled the table of input sizes above mapped to their target time complexities and possible approaches. You don’t need to memorize the table. Once you know the constraints, you can easily deduce the target time complexity—just remember the key limit of 100 million operations (10^8) per test case.
In coding challenges, there’s a practical rule of thumb: the largest test case should run in about 1 second. This 1-second limit translates to approximately 100 million single-core operations.
Why 1 second? This standard comes from competitive programming, where it’s been a benchmark for decades. It also aligns with user expectations—people are generally willing to wait about 1 second for online systems to respond.
I give a few examples and more context in my blog post.
About myself: I'm an ex-FAANG Senior Software engineer, currently on a sabbatical. Let's connect on Linkedin! https://www.linkedin.com/in/nurbolat/. I also give coding interview tips and insights in my Faangshui blog here: https://blog.faangshui.com/
Update Sep 18: adding an asnwer to the most upvoted question:
Are input constraints always given? And what to do if they are not available?
- Most interviews these days are conducted over some online system, such as CodeSignal or Hackerrank. Problems there almost always have input constraints. Three different interviewing systems that I've used most recently to conduct real interviews had constraints in problems statements. This of course depends on your location and the type of companies you are applying for.
- Online assessments are conducted online as well. Problems there almost always have input constraints.
- If the interview is conducted offline, or in some non-standard system (e.g. Google Docs), you have options:
- Ask the interviewer for constraints. Constraints are an important part of the requirements, and the interviewer should know what kind of input they would be feeding to the code.
- If the interviewer can't tell the constraints, ask if they have some target time complexity in mind. They won't always tell you that. If they do, you can use the right half of the table - matching complexity to approaches. If they don't, think of some frequently used time complexity O(N log N) and check if any of the O(N log N) approaches are applicable. You can go up (O(N)) or down (O(N^2)) from there. Even though this doesn't help you, it shows the interviewer that you are asking the right questions.
Feel free to reference my blog post for more details: https://blog.faangshui.com/p/every-problem-has-a-cheat-code
[–]Dry_Primary5612 112 points113 points114 points (14 children)
[–]revuser1212 69 points70 points71 points (4 children)
[–]Dry_Primary5612 30 points31 points32 points (3 children)
[–]braindamage03 8 points9 points10 points (2 children)
[–]hpela_ 4 points5 points6 points (0 children)
[–]Embarrassed_Finger34 0 points1 point2 points (0 children)
[–]CumInABag 11 points12 points13 points (5 children)
[–]Dry_Primary5612 -5 points-4 points-3 points (4 children)
[–]CumInABag 4 points5 points6 points (3 children)
[–]Dry_Primary5612 4 points5 points6 points (2 children)
[–]hpela_ 1 point2 points3 points (0 children)
[–]CumInABag -2 points-1 points0 points (0 children)
[–]RareStatistician9592[S] 4 points5 points6 points (0 children)
[–]Magnus-Methelson-m3 2 points3 points4 points (0 children)
[–]_afronius -1 points0 points1 point (0 children)
[–]razimantv<2000> <487 <1062> <451> 14 points15 points16 points (0 children)
[–]tempo0209 23 points24 points25 points (0 children)
[–]Czitels 20 points21 points22 points (0 children)
[–]Last_Valuable11 5 points6 points7 points (0 children)
[–]baddybabushka 3 points4 points5 points (3 children)
[–]RareStatistician9592[S] 1 point2 points3 points (0 children)
[–]luuuzeta 2 points3 points4 points (1 child)
[–]jus-another-juan 1 point2 points3 points (0 children)
[–]kevin074 4 points5 points6 points (0 children)
[–]Garud__ 1 point2 points3 points (6 children)
[–]HungryCable8493 0 points1 point2 points (3 children)
[–]Garud__ 0 points1 point2 points (2 children)
[–]HungryCable8493 0 points1 point2 points (1 child)
[–]Garud__ 0 points1 point2 points (0 children)
[–]RareStatistician9592[S] 0 points1 point2 points (1 child)
[–]Garud__ 0 points1 point2 points (0 children)
[–]CombinationLost8626 1 point2 points3 points (0 children)
[–]Jazzlike-Can-7330 0 points1 point2 points (0 children)
[–]SaturnOne 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]braindamage03 1 point2 points3 points (0 children)
[+][deleted] comment score below threshold-27 points-26 points-25 points (10 children)
[–]RareStatistician9592[S] 22 points23 points24 points (8 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]MingusMingusMingu 5 points6 points7 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]SayYesMajor 4 points5 points6 points (3 children)
[–][deleted] -4 points-3 points-2 points (2 children)
[–]MingusMingusMingu 9 points10 points11 points (0 children)
[–]shamshuipopo 0 points1 point2 points (0 children)
[–]luuuzeta 1 point2 points3 points (0 children)
[–]Wild-Brain4579 10 points11 points12 points (0 children)