Microsoft interview question

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