Microsoft Interview Question

I was asked to solve a DSA style problem.