You are given an integer array nums and an integer k.
The mode of a subarray is the element with the highest frequency in that subarray. If multiple elements share the maximum frequency, the mode is the smallest element among them.
The weight of a subarray is calculated as the product of its mode and the frequency of that mode within the subarray.
Return the total sum of the weights across all contiguous subarrays of length k.
Constraints:
nums.length
nums[i]
k nums.length
You are given an integer array nums and an integer k.
The mode of a subarray is the element with the highest frequency in that subarray. If multiple elements share the maximum frequency, the mode is the smallest element among them.
The weight of a subarray is calculated as the product of its mode and the frequency of that mode within the subarray.
Return the total sum of the weights across all contiguous subarrays of length k.
Constraints:
nums.length
nums[i]
k nums.length