Tap here to switch tabs
Problem
Submissions

Problem: Maximum Beauty of an Array After Applying Operation

Maximum Beauty of an Array After Applying Operation lets you replace each array value at most once with any integer within its allowed range, then return the longest subsequence of equal values.

Statement

You are given a 00 indexed integer array nums and a non negative integer k.

In one operation, you can:

  1. Choose any index i that has not been chosen previously.

  2. Replace nums[i] with any integer from the range [[nums[i] −- k, nums[i] ++ k]].

The beauty of the array is defined as the length of the longest subsequence consisting of equal elements.

Return the maximum possible beauty of nums after applying the operation any number of times.

Note: You can apply the operation to each index at most 11 time.

Constraints:

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

  • 0≤0 \leq nums[i], k ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Beauty of an Array After Applying Operation

Maximum Beauty of an Array After Applying Operation lets you replace each array value at most once with any integer within its allowed range, then return the longest subsequence of equal values.

Statement

You are given a 00 indexed integer array nums and a non negative integer k.

In one operation, you can:

  1. Choose any index i that has not been chosen previously.

  2. Replace nums[i] with any integer from the range [[nums[i] −- k, nums[i] ++ k]].

The beauty of the array is defined as the length of the longest subsequence consisting of equal elements.

Return the maximum possible beauty of nums after applying the operation any number of times.

Note: You can apply the operation to each index at most 11 time.

Constraints:

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

  • 0≤0 \leq nums[i], k ≤105\leq 10^5