Generation

generate functionTue, 25 Jul 2023

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

def adjacentElementsProduct(inputArray): max = inputArray[0] * inputArray[1] for i in range(1, len(inputArray) - 1): if inputArray[i] * inputArray[i + 1] > max: max = inputArray[i] * inputArray[i + 1] return max adjacentElementsProduct([3, 6, -2, -5, 7, 3])

Questions about programming?Chat with your personal AI assistant