Round 1
Questions: Your team at Amazon wants to develop a service that takes in an array of integers where the ith element represents the category of the ith product viewed by the customer and returns the sum of the number of distinct categories on all contiguous segments of the array.
Given an array of n integers, categories, find the sum of the numbers of distinct integers over all of its subarrays.
Note: A subarray is a contiguous part of an array.
For example, the subarrays of [1, 2, 3] are [1], [2], [3], [1, 2], [2, 3], [1, 2, 3].
Example: Given an array of n = 3 integers, categories = [1, 2, 1]: output = 9
Constraints
1 <= n <= 10^5
1 <= categories[i] <= 10^9
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.