Tap here to switch tabs
Problem
Submissions

Problem: Maximum Frequency Score of a Subarray

med
30 min
Try to solve the Maximum Frequency Score of a Subarray problem.

Statement

You are given an integer array nums and a positive integer k.

The frequency score of a subarray is defined as the sum of vcv^c across all distinct values vv present in the subarray, where cc denotes the number of occurrences of vv in that subarray.

Return the maximum frequency score achievable among all subarrays of length k. Since the resulting value may be large, return it modulo 109+710^9 + 7.

Note: A subarray is a contiguous sequence of elements within an array.

Constraints:

  • 1≤1 \leq k ≤\leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Frequency Score of a Subarray

med
30 min
Try to solve the Maximum Frequency Score of a Subarray problem.

Statement

You are given an integer array nums and a positive integer k.

The frequency score of a subarray is defined as the sum of vcv^c across all distinct values vv present in the subarray, where cc denotes the number of occurrences of vv in that subarray.

Return the maximum frequency score achievable among all subarrays of length k. Since the resulting value may be large, return it modulo 109+710^9 + 7.

Note: A subarray is a contiguous sequence of elements within an array.

Constraints:

  • 1≤1 \leq k ≤\leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6