DSA Learning Series Problem

Question: CodeChef: Practical coding for everyone
Submission Link: CodeChef: Practical coding for everyone

I have used unordered_map to solve this question…The sample test cases are passed but while submission wrong answer is being dislayed…Please help!.

Removing m[0] doesn’t seem to be right. You have to remove the flavor that is at the leftmost part of the array, as they are asking a contiguous subarray.

This is my submission.

P.S: Here we can just use an array to store the count instead of an unordered_map. An array promises O(1) time operations, whereas an unordered_map can blow up to O(n) time per operation. - this can be clearly seen form the run-time difference of the submissions.

1 Like