Intuit Interview Question: Write a function where, given... | Glassdoor

## Interview Question

Software Engineering Intern Interview

# Write a function where, given an index, you return the

Fibonacci number at that index.
Tags:
technical, fibonacci

0

Not too hard, but I had a very short time to do it which is what made it difficult.

Interview Candidate on Jul 9, 2013
2

Fibonacci! Here are 2 different versions (iterative, recursive):

public class Fibonacci {
public static void main(String[] args) {
int yourInt = 8;
System.out.println(findFibRecursive(yourInt));
System.out.println(findFibIterative(yourInt));
}

public static int findFibRecursive(int theirInt) {
if(theirInt <= 1) {
return theirInt;
}
return findFibRecursive(theirInt - 1) + findFibRecursive(theirInt - 2);
}

public static int findFibIterative(int theirInt) {
int[] array = new int[theirInt + 1];
array[0] = 0;
array[1] = 1;

for(int i = 2; i < theirInt + 1; i++) {
array[i] = array[i - 1] + array[i - 2];
}

return array[theirInt];
}
}

Terry on Jul 28, 2015