Le Flashcards
1
Q
Given a value n find f(n) number?
A
class Solution {
public int fib(int n) {
if(n<=1){
return n;
} else {
return fib(n-1) + fib(n-2);
}
}
}
2
Q
Describe the Fibonacci sequence
A
f(0) = 0
f(1) = 1
f(n) = f(n-1) + f(n-2)
3
Q
What is F(3)?
A
f(n) = f(n-1) + f(n-2)
f(3) = f(3-1) + f(3-2)
f3 = f(2) + f(1)
f3 = 1 + 1 = 2
4
Q
What data structure should you use to , find the length of the longest substring without repeating characters.
A
Hash Map
5
Q
Write the code for to find a Fibonacci number and what is the time complexity?
A
public int fib(int N) {
if (N <= 1) {
return N;
}
return fib(N - 1) + fib(N - 2);
}
O(N^2)