Search
⌘K

Leetcode 2916. Subarrays Distinct Element Sum of Squares II

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.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.

Leetcode 2916. Subarrays Distinct Element Sum of Squares II | Hello Interview