title: Given a fibonacci method/function, implement it and make it efficient
body: <p>Hey guys so in my interview question I was given something like this below. By the way this is my code to solve fib. I want to improve this my code to eliminate repetition of fibonacci sequence that might end up being repeated at the process. For example if fib(1) and fib(1) are repeated twice, how to do I avoid this from happening so the program can advance to unique sequence being processed. </p>
  
  <p>I really want to know how to improve this code. My solution is below but when I debug it, I feel like I get lost understanding what is really happening.</p>
  
  <p>Thanks.</p>
  
  <pre><code>public class Fib {
  
  public static void main(String[] args) {
  
      System.out.print(fibonacci(14));
  }
  
  private static int fibonacci(int n) {
  
      int fibArray[] = new int[n];
      if (n &lt;= 0) {
          return 1;
      } else if (n == 1) {
          return 1;
      } else {
          fibArray[0] = fibonacci(n - 1);
          fibArray[1] = fibonacci(n - 2);
          if (fibArray[0] == fibonacci(n - 1)) {
              return fibonacci(n - 1) + fibonacci(n - 2);
          } else if (fibArray[1] != fibonacci(n - 2)) {
              return fibonacci(n - 1) + fibonacci(n - 2);
  
          } else {
              return fibonacci(n - 1) + fibonacci(n - 2);
          }
  
      }
  }
  </code></pre>
  
  <p>}</p>