Microsoft interview question

DSA and one Puzzle question.