C++ Adjacent Elements Product
#include <algorithm>
#include <limits>
#include <vector>
long long adjacentElementsProduct(const std::vector<int>& inputArray)
{
long long max = std::numeric_limits<long long>::min();
for (std::size_t i = 0; i + 1 < inputArray.size(); ++i) {
long long product = static_cast<long long>(inputArray[i]) * inputArray[i + 1];
max = std::max(max, product);
}
return max;
}
This walks through neighboring values, multiplies each pair, and keeps the biggest product it finds.