Mr. Handyman interview question

Dsa question and leetcode medium and hard