Atlassian records daily activity as a list of integers named activity, ordered by day. A consistent activity streak is a contiguous part of this list containing at least two days, with the same difference between every pair of neighboring values.
public int longestConsistentStreak(List<Integer> activity)
activity: The activity values for consecutive days.public int longestConsistentStreakWithOneChange(List<Integer> activity)
activity: The activity values for consecutive days.2.2 ≤ activity.size() ≤ 100,0000 ≤ i < activity.size()-1,000,000,000 ≤ activity.get(i) ≤ 1,000,000,000Example calls label the argument as activity = [...] for readability.
Call: longestConsistentStreak(activity = [4, 9, 14, 31, 24, 29])
Output: 3
The streak [4, 9, 14] has a common difference of 5.
Call: longestConsistentStreakWithOneChange(activity = [4, 9, 14, 31, 24, 29])
Output: 6
Replace 31 with 19. The entire list becomes [4, 9, 14, 19, 24, 29], with a common difference of 5.
Call: longestConsistentStreak(activity = [8, 8, 8, 8])
Output: 4
Call: longestConsistentStreakWithOneChange(activity = [8, 8, 8, 8])
Output: 4
The entire list already has a common difference of 0.
Call: longestConsistentStreak(activity = [9, 2, 7, 12])
Output: 3
The streak [2, 7, 12] has a common difference of 5.
Call: longestConsistentStreakWithOneChange(activity = [9, 2, 7, 12])
Output: 4
Replace the first value, 9, with -3. The entire list becomes [-3, 2, 7, 12].
Call: longestConsistentStreak(activity = [2, 5, 9, 12])
Output: 2
No three consecutive values have a constant difference.
Call: longestConsistentStreakWithOneChange(activity = [2, 5, 9, 12])
Output: 3
Replace 2 with 1 to obtain the streak [1, 5, 9], with a common difference of 4. No single replacement can make all four values consistent.