This was a question that I solved during the Microsoft Coding Competition in September 2014