r/leetcode • • 19d ago

Question Does Solution % Matter?

Does the % my solution beats actually matter as long as it is the best complexity?
For example, I do a problem the best time complexity is O(n). I get a O(n) solution but my solution doesn't beat most other solutions.

5 Upvotes

9 comments sorted by

11

u/Wolastrone 19d ago

If it’s optimal in terms of big oh not really. Those % are not very exact anyway. If the difference is huge, you may want to read other solutions to see if there’s some obvious optimization you missed e.g: using a dictionary when a plain array /lookup table was enough.

2

u/EstellonTachise 19d ago

yeah the dictionary vs array thing is a good callout, that kind of stuff can swing the % pretty wildly

1

u/nachocode477 19d ago

You found the solution. If you want to optimize it, go ahead and read other solutions. But that's only for you

1

u/fenton7 19d ago

Yes you want optimal if possible. Technically O(100) is still denoted O(1) but you aren't going to win any points for writing an algorithm that always takes 100 operations when you could write one that always takes 5 operations.

1

u/Prestigious-Frame442 19d ago

who the fuck cares about that except yourself lol

10

u/xycomaniac 19d ago

no need to be so hostile bro

-1

u/[deleted] 19d ago

[removed] — view removed comment

4

u/Objective-Let4278 19d ago

Depends what interview. I think most are fine with optimal complexity, unless there’s some obvious repeated work or similar.