IBM interview question

Standard Coding Algorithm Question followed by SQL