DigiCollect interview question

Time Complexity