Microsoft interview question

LeetCode-style problems in both cases.