Microsoft interview question

Leetcode problems so make you practice. Also, explain your reasoning behind it.