java - Algorithm with O(n) to find min and max of triple product in subsets -


The problem is that the minimum and maximum triple product (product of 3 numbers) that can be created is the number. I did a code that did the right thing but got its complexity (N ^ 2) . I need some help in reducing it O (N) if possible

EDIT: The numbers can be both positive and negative.

Here's my code:

  import java.util. *; Class results {public static int min = 50000000; Public static max = max - 50000000; Public static int solution (integer, integer, profound depth) {if (depth == 3) {check (currPro); } Else {for (int i = 1; i & lt; = Triplet.data.length-pos; i ++) {if (pos + i & lt; Triplet.data.length) {Hull (pos + i, currPro * Triplet.data [Position + I], Depth + 1); }} 0 return 0; } Public static zero check (int.) {If (crop> max) {max = currPro; } If (currPro  

try it

  1. Find three With the quick sort division in O (n) time, the smallest and the three largest numbers (whether negative or positive ones)
  2. Apply your O (N ^ 2) solution to the 6-digit array.

Time to walk - O (n)


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -