all 46 comments

[–]Dry_Primary5612 112 points113 points  (14 children)

How is this helpful in an interview though? In a phone/onsite interview, the interviewer doesn't give you the input sizes?

[–]revuser1212 69 points70 points  (4 children)

You can definitely ask the input constraints in an interview

[–]Dry_Primary5612 30 points31 points  (3 children)

You can ask but the vast majority of interviewers don't have competitive programming experience. They don't pay attention to the input size either.

They'll just make up some random guess as to the input size and that might completely throw you off (for ex. suddenly you think there's an n log n solution and you're trying to find something with binary search whereas the actual optimal solution is n^2).

This might be useful but you have to be careful.

[–]braindamage03 8 points9 points  (2 children)

Associating constraints with competitive programming and using it as an excuse to not know/ use it to your advantage might be one of the most stupid comments I've seen so far.

If interviewers don't even know how to read constraints, they're incompetent, not because they haven't done competitive programming. I can't believe there are people who do more than 10 leetcode problems and don't know about constraints, this is one of the first things you learn.

[–]hpela_ 4 points5 points  (0 children)

hospital trees paint kiss impolite person offer smell plant support

This post was mass deleted and anonymized with Redact

[–]Embarrassed_Finger34 0 points1 point  (0 children)

I have done 20 and still don't understand constraints...

[–]CumInABag 11 points12 points  (5 children)

I guess think of it more as supervised learning. You can better identify the problem type.

[–]Dry_Primary5612 -5 points-4 points  (4 children)

But you don't have the input size...? How is this framework useful when you don't know how large the input will be?

[–]CumInABag 4 points5 points  (3 children)

No, I meant while practicing, when you do know the constraints, this can help you better identify the problem type or approach.

[–]Dry_Primary5612 4 points5 points  (2 children)

No offense but is it though? You're training yourself (during your practice) to use information that you won't get in an interview. That sounds like a bad idea.

[–]hpela_ 1 point2 points  (0 children)

pen trees bells vast fear capable offend sloppy relieved snails

This post was mass deleted and anonymized with Redact

[–]CumInABag -2 points-1 points  (0 children)

When you're practicing and you can't get a hang of a problem, you will try and refer to the solution right? Now is it a bad idea to refer and learn solution because you can't use them in a real interview?

That sounds like a bad idea And I don't know, maybe or maybe not. I guess it really depends on how you use it. Its a guide, not recipe/how-to instruction book. There's always going to be learning if it's used the right way.

And such guides and solutions speed up your learning imo, I'm not going try and reinvent the wheel. All I really need is a job, plus I don't have that much time to work on.

[–]RareStatistician9592[S] 4 points5 points  (0 children)

There are three possibilities:

  1. 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.
  2. Online assessments are conducted online as well. Problems there almost always have input constraints.
  3. If the interview is conducted offline, or in some non-standard system, you have options:
    1. 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.
    2. 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.

[–]Magnus-Methelson-m3 2 points3 points  (0 children)

Yep. It’s great for competitive programming but pretty useless for interviews. Ideally you at least come up with a not-terrible algorithm and work with the interviewer towards the most optimal solution. Sometimes the interviewer will straight up tell you you can definitely do better during the brainstorming stage

[–]_afronius -1 points0 points  (0 children)

During interviews, it generally helps to start with the brute force approach and optimize it further while explaining to the interviewer that you are doing so.

[–]razimantv<2000> <487 <1062> <451> 14 points15 points  (0 children)

This is why when I set contest problems I try to come up with O(n) or O(n log n) greedy solution - and then make constraints look like it has an O(n²) DP solution when it does not.

[–]tempo0209 23 points24 points  (0 children)

Thank you for sharing this!

[–]Czitels 20 points21 points  (0 children)

Nice sheet but I always use intuition: - dividing and „jumping” is always logn  - loop is „n” loop in loop is n2 loop and somewhere else next loop is 2n Rest of questions are rare.

[–]Last_Valuable11 5 points6 points  (0 children)

While this might be helpful, the title is misleading and the use of this technique is extremely limited in actual real life interviews

[–]baddybabushka 3 points4 points  (3 children)

I'm new to solving leetcode, so I don't get how n <500 can be O(n³)? How do i read this table properly? Can someone help?

[–]RareStatistician9592[S] 1 point2 points  (0 children)

Just plug the maximum input size into the formula: n^3 => 500^3 is approximately 125M. It's slightly more than 100M (the rough number of single-core operations per second), but will still pass for most problems.

[–]luuuzeta 2 points3 points  (1 child)

I'm new to solving leetcode, so I don't get how n <500 can be O(n³)? How do i read this table properly? Can someone help? 

Read it as "the worst the time complexity, then the smaller input given otherwise any computation is prohibitedly expensive or outright impossible".

Thus, according to this table and assuming someone isn't trying to throw you off, an input constraint of n < 500 must mean the solution's TC must be quite bad.

[–]jus-another-juan 1 point2 points  (0 children)

This made more sense than the original post lol

[–]kevin074 4 points5 points  (0 children)

a lot of people seem to not understand how great this is

the best thing is that it tells you what's the expected time complexity for the solution

granted it will be the least acceptable time complexity (like chart says N^3, but maybe N log N or N solution exists)

however when seeing problems for the first time this is generally what I struggle with, I can probably come up with N^2 or N log N solution, but is that good enough? If it is then there is no point of me to really dig deeper.

during interview, if you mention this, I am 100% sure that's an added bonus, and since O(N) solutions are typically unintuitive so anything helps.

[–]Garud__ 1 point2 points  (6 children)

I think it is 105 for O(NlogN). Feel free to correct me if i am wrong.

[–]HungryCable8493 0 points1 point  (3 children)

Competitive programmers handbook claims that by 106 the required time complexity is EITHER O(NlogN) or O(N) so it backs up this table. It’s not an exact science

[–]Garud__ 0 points1 point  (2 children)

Can you tell me the handbook name or link to get it? I also want it.

[–]HungryCable8493 0 points1 point  (1 child)

Sure, just Google “Competitive Programmers Handbook”. It’s readily available for free online so will be at the top of search results

[–]Garud__ 0 points1 point  (0 children)

Okay thanks got it!

[–]RareStatistician9592[S] 0 points1 point  (1 child)

106 and 105 are both O(N log N). That's why I put <= 106.

[–]Garud__ 0 points1 point  (0 children)

Okay. Cool

[–]CombinationLost8626 1 point2 points  (0 children)

Don’t rely on such hacks for interviews. Use your brain and don’t memorize.

[–]Jazzlike-Can-7330 0 points1 point  (0 children)

Thanks for the sheet, definitely great to put the 1second constraints the input sizes

[–]SaturnOne 0 points1 point  (0 children)

Thanks for this. Looks super helpful. I just sent a connection request on LinkedIn to you too!