This is a sample interview problem that is pretty popular.  I wanted to have my own solution on hand just to compare to candidates.