title: Find the GCD for given array of elements
body: <p>I had faced a interview question to find the gdc(greatest common divisor) for an integer array of element in optimised way :</p>
  
  <pre><code>Sample case :
     a[] = { 10,20,19,15,13}
  
  Result = 1
  
  sample case : 
    a[]={9,21,12,15,27}
  Result : 3
  </code></pre>
  
  <p>I have submitted following result during the interview. But he asked to optimise the same. Solution which I proposesd:</p>
  
  <pre><code>package threeDpalm;
  
  public class GCF
  {
      public static void main(String ag [])
      {
          int[] input = {10, 20, 3, 30, 90, 40};
          boolean flag = true;
          int min_araay = Integer.MAX_VALUE;
          int count = 0;
          while (flag)
          {
              for (int j : input)
              {
  
                  if (j &lt; min_araay &amp;&amp; j != 0)
                  {
                      min_araay = j;
                  }
              }
              for (int k = 0; k &lt; input.length; k++)
              {
                  input[k] = input[k]%min_araay;
                  if (input[k] == 0)
                  {
                      count++;
                      if (count == input.length)
                      {
                          flag = false;
                          System.out.println(min_araay);
                          break;
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Can some one please help me with better solution</p>