Microsoft interview question

Leetcode type easy middle hard