Microsoft Interview Question

DSA and one Puzzle question.