Microsoft interview question

Two problems with medium difficulty to solve