Groww interview question

Hard level question of leetcode