Notice
Recent Posts
Recent Comments
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

CHIqueen

[Intro] adjacentElementsProduct 본문

프로그래밍/CodeSignal

[Intro] adjacentElementsProduct

CHIqueen 2020. 3. 3. 17:48

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.

def adjacentElementsProduct(inputArray):
    return max([inputArray[i] * inputArray[i+1] for i in range(len(inputArray)-1)])

그냥 다 곱한다음에 max함수로 구해줬다.

'프로그래밍 > CodeSignal' 카테고리의 다른 글

[Intro] shapeArea  (0) 2020.03.03
[Intro] Make Array Consecutive 2  (0) 2020.03.03
[Intro] checkPalindrome  (0) 2020.02.26
[Intro] centuryFromYear  (0) 2020.02.26
[Intro] add  (0) 2020.02.26
Comments