Available question text
Compute the sum over all nonempty subarrays of (number of distinct elements)^2 in an integer array, returning the result modulo 1e9+7. With n up to 1e5, the core challenge is to avoid O(n^2) enumeration by algebraically expanding the square into per-element and pairwise contributions and counting those efficiently using occurrence tracking.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 2916. Subarrays Distinct Element Sum of Squares II
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source