반응형

Given an array of integers, find the maximal absolute difference between any two of its adjacent elements.


Example


For inputArray = [2, 4, 1, 0], the output should be

arrayMaximalAdjacentDifference(inputArray) = 3.


code >>


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

int max = -987654321;

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

{

max = std::max(max, std::abs(inputArray[i] - inputArray[i + 1]));

}

return max;

}

반응형

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

22>avoidObstacles  (0) 2017.07.05
21>isIPv4Address  (0) 2017.07.04
19>areEquallyStrong  (0) 2017.07.02
18>palindromeRearranging  (0) 2017.07.02
17>arrayChange  (0) 2017.07.01

+ Recent posts