title: Algorithm that finds the maximum product - Analysis
body: <p>I have this code which is calculating the largest product you can find using 3 numbers in an array:</p>
  
  <pre><code>public static int findMaxProduct(int[] arr) {
  
          int i=0, j=1, f=2;
  
          int largest = arr[i]*arr[j]*arr[f];
          for(;i&lt;arr.length;) {
              if(largest&lt;arr[i]*arr[j]*arr[f])
                  largest = arr[i]*arr[j]*arr[f];
  
              if(i==arr.length-3)
                  return largest;
  
              if(f==arr.length-1 &amp;&amp; j == arr.length - 2) {
                  i++;
                  j=i+1;
              }
              if( f==arr.length-1 &amp;&amp; j != arr.length-2) 
                  f = j+1;
  
              if(f&lt;arr.length-1)
                  f++;
              if(f==arr.length -1 &amp;&amp; j &lt; arr.length -2)
                  j++;
  
  
  
  
          }
          return 0;
      }
  </code></pre>
  
  <p>Now, I am not sure of what complexity it is, as we increment <code>i</code> if only a condition is met, and we don't know where it's going to execute <code>i++</code> . I would appreciate if you help me find the complexity! (Time)</p>