Microsoft interview question

Leetcode