Microsoft Interview Question

The first question was average in difficulty and the second one was a dynamic problem.