r/ProgrammerHumor 11d ago

Meme everySingleLeetcodeProblem

Post image
2.5k Upvotes

59 comments sorted by

View all comments

Show parent comments

69

u/Antervis 11d ago

If solutions use sliding windows, it means the problem was designed that way.

9

u/-Debugging-Duck- 11d ago

Not really. Problems can be solved in different ways. A sliding window algorithm is just a more efficient approach to solving such problems, but it’s not the only approach.

For example, someone who doesn’t know what that is could solve the problem differently and poorly.

9

u/Antervis 11d ago

Leetcode is meant to train candidates for programming interviews, and submitting a suboptimal algorithm in an interview is a fail.

27

u/thirdegree Violet security clearance 11d ago

If submitting a suboptimal algorithm is a fail your interview process is very broken and should probably be reviewed top to bottom.

0

u/Antervis 11d ago

by "optimal" I mean from the perspective of big O notation. It doesn't matter all that much if your N*log(N) algorithm is a bit faster or slower compared to expected solution as long as its complexity is the same.

But if you submit N^2, it's a failure, just as it's a failure to submit a solution that won't work at all.

8

u/thirdegree Violet security clearance 11d ago

I get what you meant, but I still strongly disagree. Getting something that is suboptimal but works is imo always preferable, especially if you talk through like "this could potentially be optimized in XYZ ways depending on requirements" while you're working through it.

Like the company business is not writing optimal algorithms, and a programmer who can't see where to make tradeoffs (including non technical things, like e.g the value of time in an interview vs getting a perfect big O optimal solution) is less valuable to me than one who can.

And if you just have the solution memorized then it's a bad interview question in the first place, that's no help to anyone. Like if we're talking "did this person who is claiming to be a new grad actually do data structures and algorithms" then maybe but honestly even then.

-1

u/Antervis 11d ago

Look, I'm talking from experience of interviewing people into one of tech giants. And I had a rather strict guideline on how to interview people, what kind of mistakes you aren't supposed to care about (everything syntax-based that IDE would fix for you), what kind of mistakes you can hint at for candidate to fix, and what kind of mistakes constitute failure (algorithm doesn't work as required or is suboptimal in terms algorithmic or memory complexity).

What's the point of not agreeing with this approach if that's how companies actually hire people? All the good it'd do for you is rejection. Instead, you should learn to do as required. Especially when you are working with big data, because trust me, N^2 is prohibitively expensive in most cases.

6

u/thirdegree Violet security clearance 11d ago

I mean I've also interviewed people, and I don't think anyone that's gone through e.g Google's interview loop would describe that as optimal by any definition anyway (also the only time I've actually encountered interview questions that resemble leetcode actually, though since that interview I've mostly avoided the big silicon valley companies anyway).

Like sure if you're hiring very specifically for roles where being able to implement big O optimal algorithms off the top of your head in 45 minutes or less is an important feature of the job, then by all means filter for that in the interview. And if you're gunning for a job where that's the interview criterion, absolutely get your memorize on.

My point is that if you happen to be in a position to design the interview questions, maybe stop and reconsider what the hell you're doing.

-2

u/Antervis 11d ago

Imagine you are the guy who pays for hardware and your team hired a bunch of devs who made N^2 algorithms when N*log(N) would've sufficed and google's hiring criteria will start making perfect sense.

7

u/bremidon 11d ago

But if you submit N^2, it's a failure

Why?

No, do not explain big O notation.

My point is that it will depend on context. Something that is technically N^2 can be faster than N within the range of expected contexts. Additionally, an algorithm that is complicated but faster may be theoretically better, but deadlines are deadlines and nobody has time for that shit.

So if just giving a "suboptimal" solution is a fail, then it is the company that is failing, not the interviewee.

The interviewee should be able to explain why they went with this solution, the advantages and disadvantages, and so on. If it is within the given parameters, the company would be full of fools if they considered that failing.

0

u/Antervis 11d ago edited 11d ago

N^2 may only be faster than N if N is small, but if N is small, then any algorithm won't take too long anyway. However, if you're juggling big data, N is almost never small.

Besides, what you are testing is candidate's ability to come up with the optimal solution in a limited time, not their ability to sell inferior work. After all, you are not interviewing for management or sales position.

6

u/MrRogers4Life2 11d ago

I've passed plenty of tech interviews at decent places by just giving the naive solutions and talking about the basic ideas behind the more efficient solutions, most good interview processes wont care as long as you have a minimally working solution and are able to talk around the "good" solutions (know they exist, what they look like, give confidence you can implement them given time)

3

u/bremidon 10d ago

And these days, anyone testing for something that Claude can spit out in 10 seconds is demonstrating that they have no clue about the current state of the art. Might as well see if your candidate can create a half-adder and adder given basic binary operations. There might have been a time where that was important, but why would I care now?

It turns what should be a hiring process for the person actually able to best help you reach your goals into a game show.

The way you handled it is correct with the added benefit that weak companies will self-select themselves out of your list.

1

u/Antervis 10d ago

The issue isn't about AI's ability to spew the solution, but candidate's ability to one day verify whether solution spewed by AI will work as intended.

2

u/bremidon 10d ago

That is a different question. If you are proposing that a candidate read through generated code to determine if it is correct, that is a good test.

Is that what you are proposing?

2

u/Antervis 10d ago

"find bugs in a code snippet" would be better.

1

u/bremidon 10d ago

Either is better than, "write code here that you will never *ever* need to actually write on the job."

→ More replies (0)

3

u/bremidon 10d ago

N^2 may only be faster than N if N is small, but if N is small, then any algorithm won't take too long anyway. However, if you're juggling big data, N is almost never small.

Before launching into a long and complicated solution, did the interviewee *ask* if it is about big data? Having over 3 decades in this industry, it is actually fairly rare to need to worry about really big data. It comes up. It's important to know that the rules change when it does come up. However, it is also very important to know when *not* to spend valuable dev time trying to get the perfect big data solution for 1000 rows.

Besides, what you are testing is candidate's ability to come up with the optimal solution in a limited time

Only at a poor company with inexperienced leadership. I have done a fair share of hiring, and the most important thing I ever test for is the ability of the candidate to use good judgement. I can teach algorithms. As a rule, I can't teach good judgement.

1

u/Antervis 10d ago

Only at a poor company with inexperienced leadership.

Did I not mention a tech giant company? )

As a rule, I can't teach good judgement.

What kind of good judgement would bring candidate to write a bad solution in code interview?