General
What's the most elegant solution you've ever seen?
11 months ago
274
Share solutions that made you go "wow, that's genius!" For me it was:
Boyer-Moore Voting Algorithm for finding the majority element. The idea that you can cancel out non-majority elements is so elegant.
Dutch National Flag for 3-way partitioning. Simple but the pointer movements are beautiful.
Floyd's Cycle Detection - using fast/slow pointers to detect cycles. The math behind why it works is fascinating.
What's your favorite?
algorithmselegantdiscussionfavorite