Count Distinct Categories

Problem Overview

  • Compute the total number of distinct categories across all contiguous subarrays of an integer array.
  • Input: int array categories (length n); Output: long integer sum of distinct counts over all subarrays.
  • Real-world context: models customer product category views in an Amazon service.
  • This Amazon interviews coding interview problem is a common interview question about arrays and subarrays.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: