Longest Consistent Activity Streak
Problem statement
A consistent streak is a contiguous arithmetic sequence: every adjacent difference is equal. Replace at most one element with any integer and return the greatest possible streak length.
A nonempty array of length one has streak length one; no modification is required.
Function
longestConsistentStreak(activity: int[]) → intExamples
Example 1
activity = [1,2,10,4,5]return = 5Replace 10 with 3 to obtain difference one throughout.
Example 2
activity = [1,2,3,8,9,10]return = 4One replacement can extend either arithmetic run by one.
Constraints
1 <= activity.length <= 200000.- Values fit signed 32-bit integers; replacements may be any integer.
Source note: Author-written prompt excerpt retained for source fidelity.