A solution to the common interview question, in C