Tally Solutions interview question

Dsa based with some puzzles