Solutions
CodeSignal
CodeSignal
  • Home
  • Arcade
    • Intro
      • The Journey Begins
      • Edge of the Ocean
Powered by GitBook
On this page

Was this helpful?

  1. Arcade
  2. Intro

Edge of the Ocean

adjacentElementsProduct

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.

int solution(int[] inputArray) {
    int largestProduct = inputArray[0] * inputArray[1];
    for(int i=0; i<inputArray.Length-1;i++){
        if(inputArray[i] * inputArray[i+1] > largestProduct)
            largestProduct = inputArray[i] * inputArray[i+1];
    }
    return largestProduct;
}
PreviousThe Journey Begins

Last updated 2 years ago

Was this helpful?