FastPrepLongest Consistent Activity Streak

Longest Consistent Activity Streak

Atlassian logoAtlassian● HardFULLTIMEPHONE SCREEN
Learn

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[]) → int

Examples

Example 1

activity = [1,2,10,4,5]return = 5

Replace 10 with 3 to obtain difference one throughout.

Example 2

activity = [1,2,3,8,9,10]return = 4

One 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.

More Atlassian problems

See Atlassian hiring insights
public int longestConsistentStreak(int[] activity) {
    // Write your code here.
}
activity[1,2,10,4,5]
expected5
Checking account…