We help IT Professionals succeed at work.
Get Started

Fibonacci challenge

Last Modified: 2016-09-11

I am working on below challenge

Psedo code:
1. if first two numbers return same
2. else call same fibonacci method by passing n-1 and n-2 and sum it up

public int fibonacci(int n) {
   if ((n == 0) || (n == 1)) // base cases
      return n;
      // recursion step
      return fibonacci(n - 1) + fibonacci(n - 2);


Open in new window

I am passing all tests
Expected      Run            
fibonacci(0) → 0      0      OK      
fibonacci(1) → 1      1      OK      
fibonacci(2) → 1      1      OK      
fibonacci(3) → 2      2      OK      
fibonacci(4) → 3      3      OK      
fibonacci(5) → 5      5      OK      
fibonacci(6) → 8      8      OK      
fibonacci(7) → 13      13      OK      
other tests

How to improve/modify my design, code and any other alternate approaches. please advise
Watch Question
phoffric I like MATLAB because I enjoy the applicable applications.
This problem has been solved!
Unlock 6 Answers and 11 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE