- Related Questions & Answers
- Maximum product of any two adjacent elements in JavaScript
- JavaScript: Adjacent Elements Product Algorithm
- Maximum sum of difference of adjacent elements in C++
- Maximum product of 4 adjacent elements in matrix in C++
- Maximum Sum Decreasing Subsequence in C++
- Maximum sum such that no two elements are adjacent in C++
- Maximum set bit sum in array without considering adjacent elements in C++
- Multiply Adjacent elements in Python
- Finding element greater than its adjacent elements in JavaScript
- Maximum sum such that no two elements are adjacent - Set 2 in C++
- Maximum sum in circular array such that no two elements are adjacent in C++
- Maximum sum such that no two elements are adjacent Alternate Method in C++ program
- Longest decreasing subsequence subarray in JavaScript
- Maximum length subarray with difference between adjacent elements as either 0 or 1 in C++
- Maximum length subsequence with difference between adjacent elements as either 0 or 1 in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

We are given an array of integers, and we are required to find the maximal absolute difference between any two of its adjacent elements.

For example: If the input array is −

const arr = [2, 4, 1, 0];

Then the output should be −

const output = 3;

because, the maximum absolute difference is in the elements 4 and 1.

The code for this will be −

const arr = [2, 4, 1, 0]; const maximumDecreasing = (arr = []) => { const res = arr.slice(1).reduce((acc, val, ind) => { return Math.max(Math.abs(arr[ind] − val), acc); }, 0); return res; }; console.log(maximumDecreasing(arr));

And the output in the console will be −

3

Advertisements