#Given an array of integers an operation
1 messages · Page 1 of 1 (latest)
thinking loud - only thing common in elements of AP is their difference. So, let's approach the problem from this perspective. create difference array[2, 2, 1, 3, 2, 6]. find the most common difference (2 here). Now just check if a[i] = a[i-1] + most_common_diff(2). If not, track set a[i] = a[i-1] + mcd(2). This should give desired result. 2 in this case.