IBM interview question

One algorithm problem, and one SQL problem.