알고리즘/codefights

4>adjacentElementsProduct

Diademata 2017. 6. 28. 17:22
반응형

Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.


Example


For inputArray = [3, 6, -2, -5, 7, 3], the output should be

adjacentElementsProduct(inputArray) = 21.


7 and 3 produce the largest product.


code>>


int adjacentElementsProduct(std::vector<int> inputArray) {

int max = -1000 * 1000;

for (int i = 0; i < inputArray.size() - 1; i++)

{

int val = inputArray[i] * inputArray[i + 1];

if (max < val)

max = val;

}

return max;

}

반응형

'알고리즘 > codefights' 카테고리의 다른 글

6>makeArrayConsecutive2  (0) 2017.06.28
5>shapeArea  (0) 2017.06.28
3>checkPalindrome  (0) 2017.06.28
2>centuryFromYear  (0) 2017.06.28
1>add  (0) 2017.06.28