Skip to content

Practice Maximum Frequency After Subarray Operation

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3434
LeetCode Problem

Maximum Frequency After Subarray Operation

Problem Statement

Choose one nonempty contiguous subarray of nums and add a single integer x to every entry in that subarray. You may choose x = 0. Given k, return the maximum possible number of entries equal to k after this operation.

Source: Maximum Frequency After Subarray Operation on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,3,4,5,6], k = 1
Output
2

# Example 2

Input
nums = [10,2,3,4,5,5,4,3,2,2], k = 10
Output
4

Constraints

1 <= n == nums.length <= 10^5
1 <= nums[i] <= 50
1 <= k <= 50

Related LeetCode Problems

Practice more problems similar to Maximum Frequency After Subarray Operation.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.