Dunzo interview question

Sequential Question - codeforces Medium/Hard question from leetcode