#3434
Maximum Frequency After Subarray Operation
medium · 30.9% accepted · 266 likes · top 8%
array · hash table · dynamic programming · greedy · enumeration · prefix sum
Description
You are given an array nums of length n. You are also given an integer k.
You perform the following operation on nums once:
- Select a subarray nums[i..j] where 0 <= i <= j <= n - 1.
- Select an integer x and add x to all the elements in nums[i..j].
Find the maximum frequency of the value k after the operation.
Solution