You are given a 1-indexed integer array nums.
You can choose two distinct values x and y and perform the following operation at most once:
x in nums with y.Return the maximum possible number of pairs of adjacent elements that are equal after performing the operation.
Example 1:
Input: nums = [1,2,3,2]
Output: 2
Explanation:
x = 3 and y = 2.[1, 2, 2, 2].(nums[2], nums[3]) and (nums[3], nums[4]).Example 2:
Input: nums = [1,2,1,2,1]
Output: 4
Explanation:
x = 1 and y = 2.[2, 2, 2, 2, 2].(nums[1], nums[2]), (nums[2], nums[3]), (nums[3], nums[4]), and (nums[4], nums[5]).Example 3:
Input: nums = [1,1,1]
Output: 2
Explanation:
[1, 1, 1].(nums[1], nums[2]) and (nums[2], nums[3]).Constraints:
2 <= nums.length <= 1051 <= nums[i] <= 109Loading editor...
[1,2,3,2]