Adjacent Elements Product
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.
[ 3, 6, -2, -5, 7, 3 ]
Explanation. The pair of adjacent elements with the largest product is 7 and 3, which gives the product 21.
[ -1, -2, -3, -4 ]
Explanation. The pair of adjacent elements with the largest product is -3 and -4, which gives the product 12.
[ 5, 1, 2, 3, 1, 4 ]
Explanation. The pair of adjacent elements with the largest product is 2 and 3, which gives the product 6.
[ 1, 5, 10, 9, 1 ]
Explanation. The pair of adjacent elements with the largest product is 10 and 9, which gives the product 90.
Follow-up: How would you modify your solution if you had to find the smallest adjacent product instead?
The input array will have at least two elements.
- Views
- 3