Microsoft interview question

A medium dificulty leetcode problem