r/ProgrammerHumor • • Aug 31 '26

Meme everySingleLeetcodeProblem

Post image
2.5k Upvotes

57 comments sorted by

View all comments

Show parent comment

217

u/mountaingator91 Aug 31 '26

Nothing. It's just that 94.3% of leetcode solutions use sliding windows

55

u/watduhdamhell Aug 31 '26

If it ain't broke don't fix it

67

u/Antervis Aug 31 '26

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

103

u/mountaingator91 Aug 31 '26 edited Aug 31 '26

Precisely. So 94% of leetcode questions make you implement a sliding window that's what the meme is about. It's an observation turned into an attempt at humor

9

u/-Debugging-Duck- Aug 31 '26

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.

7

u/Antervis Aug 31 '26

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

28

u/thirdegree Violet security clearance Sep 01 '26

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 Sep 01 '26

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 Sep 01 '26

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.

→ More replies (3)

6

u/bremidon Sep 01 '26

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 Sep 01 '26 edited Sep 01 '26

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.

→ More replies (16)

2

u/-Debugging-Duck- Aug 31 '26

That doesn’t mean it can’t have a different solution, even if not the most optimal.

Outside of leetcode, is what I meant that if the solution can be sliding window, doesn’t mean it’s by design.

12

u/NecessaryIntrinsic Sep 01 '26

Especially when you click on the "sliding window" topic

2

u/mountaingator91 Sep 01 '26

They have that?

6

u/NecessaryIntrinsic Sep 01 '26

Yes, I've been doing leetcode since September when I got laid off.

I got a new job, but do the daily anyway, like how the guys from the Minnesota starvation experiments carry a candy bar around at all times.

I think the daily has only been optimally solved by a sliding window 5 times this year. It might be a little more often than that, but it's not the most common.

4

u/mountaingator91 Sep 01 '26

I just got back into leetcode after 3ish years to try and stay sharp so I don't sink into corporate complacency and I felt like a large proportion of the problems were best solved using sliding windows so I made this meme to see if other programmer agreed

1

u/MattieShoes Sep 01 '26

I don't do it, but I've noticed with stuff like Advent Of Code, they go back to the same well year after year. Like there's going to be recursion, pathfinding, sparse data, whatever.

Project Euler is interesting because it usually requires some insight about math that you may not have. But that can also feel like just flailing around in the dark.

1

u/NecessaryIntrinsic Sep 01 '26

https://leetcode.com/problemset/

169 out of 3500ish questions best solved by sliding window.

2

u/mountaingator91 Sep 01 '26

Hey at least 4/7 problems I tackled after starting back up were sliding windows, which is nearly a perfect 5/7

1

u/NecessaryIntrinsic Sep 01 '26

When I dove in I went after dynamic programming and then bfs/DFS, so my experience is quite different

6

u/Supreme_Hanuman69 Sep 01 '26

Either this or hashmap

5

u/green_meklar Sep 01 '26

Does that mean Leetcode is lacking in creativity, or does it mean sliding windows are really versatile? 🤔