Microsoft Interview Question

A medium dificulty leetcode problem