C++ Array Maximal Adjacement Difference
#include <algorithm>
#include <cstdlib>
#include <vector>
long long arrayMaximalAdjacentDifference(const std::vector<int>& a)
{
long long dif = 0;
for (std::size_t i = 1; i + 1 < a.size(); ++i) {
long long left = std::llabs(static_cast<long long>(a[i]) - a[i - 1]);
long long right = std::llabs(static_cast<long long>(a[i]) - a[i + 1]);
dif = std::max({dif, left, right});
}
return dif;
}
This checks the gap between each pair of neighbors and returns the largest difference.