Southbay Robotic and Coding Center
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Challenge 1

Go down

Challenge 1  Empty Challenge 1

Post by Admin Mon Aug 21, 2017 12:10 pm

[b]Challenge Question:[/b]
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.

Input/Output
•[input] array.integer inputArray

An array of integers containing at least two elements.

Guaranteed constraints:
2 ≤ inputArray.length ≤ 10 ,
-1000 ≤ inputArray[i] ≤ 1000 .


•[output] integer

The largest product of adjacent elements.
Admin
Admin
Admin

Posts : 25
Join date : 2017-08-17
Location : Torrance CA

http://southbayrobot.com

Back to top Go down

Challenge 1  Empty Re: Challenge 1

Post by Admin Mon Aug 28, 2017 2:49 pm

int adjacentElementsProduct(int[] inputArray) {

int maxproduct=-1000000;
int product;
for (int i=0; i<inputArray.length-1; i++)
{

product=inputArray[i]*inputArray[i+1];
if (product>maxproduct)
maxproduct=product;
}


return maxproduct;
}
Admin
Admin
Admin

Posts : 25
Join date : 2017-08-17
Location : Torrance CA

http://southbayrobot.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum