Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Search
⌘K
Get Premium
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.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.