How My Worst Complexity Solution Beat 100% Runtime

How My Worst Complexity Solution Beat 100% Runtime

3 8
calendar_todayschedule1 min read

I recently solved the Leetcode 868. Binary Gap problem in Go, and encountered something interesting.

My supposedly worst solution — with an O(n log n) time complexity — ended up beating 100% of submissions in runtime.

Meanwhile, the "optimal" space version used more memory.

That made me realise something important:

Big-O complexity might not always dominate — especially when input size is tightly bounded.

In this case, the maximum binary length was only 32 bits. Sorting a handful of integers becomes effectively constant time. The theory said one thing. The measurements told another story.

I wrote a short breakdown explaining:

  • Why does this happen
  • How online judges measure performance
  • When asymptotic complexity truly matters
  • And how to implement a truly optimal bitwise version

If you're into performance reasoning and algorithm trade-offs, you might enjoy this one.

https://dev.to/rezzcode/leetcode-sunday-4-1025

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelskiverified - Apr 23

Systems Thinking: Thriving in the Third Golden Age of Software

Tom Smithverified - Apr 15

Demystifying Time and Space Complexity for Beginners

Saptarshi Sarkar - Feb 3

Why Space & Time Complexity Matters in Your Code ?

yogirahul - Oct 2, 2025

Cyclic Sort Made Simple: Learn the Basics and How It Works

Saptarshi Sarkar - Jan 10
chevron_left
782 Points11 Badges
2Posts
1Comments
1Connections

Related Jobs

View all jobs →

Commenters (This Week)

3 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!