3434. Maximum Frequency After Subarray Operation Medium
1/**
2 * [3434] Maximum Frequency After Subarray Operation
3 *
4 * You are given an array nums of length n. You are also given an integer k.
5 * You perform the following operation on nums once:
6 *
7 * Select a <span data-keyword="subarray-nonempty">subarray</span> nums[i..j] where 0 <= i <= j <= n - 1.
8 * Select an integer x and add x to all the elements in nums[i..j].
9 *
10 * Find the maximum frequency of the value k after the operation.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">nums = [1,2,3,4,5,6], k = 1</span>
15 * Output: <span class="example-io">2</span>
16 * Explanation:
17 * After adding -5 to nums[2..5], 1 has a frequency of 2 in [1, 2, -2, -1, 0, 1].
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">nums = [10,2,3,4,5,5,4,3,2,2], k = 10</span>
22 * Output: <span class="example-io">4</span>
23 * Explanation:
24 * After adding 8 to nums[1..9], 10 has a frequency of 4 in [10, 10, 11, 12, 13, 13, 12, 11, 10, 10].
25 * </div>
26 *
27 * Constraints:
28 *
29 * 1 <= n == nums.length <= 10^5
30 * 1 <= nums[i] <= 50
31 * 1 <= k <= 50
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/maximum-frequency-after-subarray-operation/
37// discuss: https://leetcode.com/problems/maximum-frequency-after-subarray-operation/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn max_frequency(nums: Vec<i32>, k: i32) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_3434() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.