A binary search realisation about the 1972 Stealer's Wheel song "Stuck in the Middle With You" that went too far...
The lyrics to the song "Stuck in the Middle With You" by Stealer's Wheel famously go: "Clowns to the left of me, jokers to the right here I am stuck in the middle with you". This came on the radio as I was driving one day, and coincidentally I had been practising DSA for interviews around this time. There we have the dumbest realisation ever: that lyric forms a monotonic condition that is ideal for performing binary search.
We can form the following LeetCode-esque problem statement:
The steps that the binary search algorithm takes to find his position are very simple:
I have written a very short (< 200 LOC) program to demonstrate this. It will generate an array with a random number of clowns and jokers, and place the guy in the middle then solve it using binary search. The user can specify how many people there are in total and it prints out its steps using emojis (cringe, I know - make sure your terminal supports unicode). For lyrical accuracy it includes his girlfriend in the array as well - stuck in the middle with you.
Video Feature - You can Binary Search SONG LYRICS???