I solved the algorithm and now the task was to solve the algorithm; the input is an array of numbers;

public int maxProduct(int input[]) { int maxProductValue= input[0]*input[1]; for (int i =1 ; i<input.length;i++){ if (maxProductValue<input[i]*input[i-1]) maxProductValue=input[i]*input[i-1]; } return maxProductValue; } 

Everything works but something tells me that I can decide more beautifully. I will be grateful for the decision

  • So the question is solved or not? - Antonio112009
  • No, I still consider my approach slow. And I’m waiting for an answer - elik
  • At a minimum, the product could be counted once (from the point of view of the beauty of the code), and if be replaced with maxProductValue = max(maxProductValue, input[i]*input[i-1]); - PashaPash
  • and input [i-1] to the local variable save from the last iteration - PashaPash

0