Microsoft Interview Question

I have been asked to complete two exercises in leetcode style.