## Intuit Interview Question for Software Engineer / Developers

Comment hidden because of low score. Click to expand.
1
of 1 vote

Matrix m = new Matrix(new row(1,1), new row(1,0));

Matrix FibN = m.power(n);

return FibN.Row(1).Column(1)

// Assume some implementation of Matrix...
// m = [1 1]
// [1 0]
//

Comment hidden because of low score. Click to expand.
1
of 1 vote

import java.util.ArrayList;

public class Fibonacci {

private ArrayList<Integer> generateFibonacci (int n){
ArrayList<Integer> fib=new ArrayList<Integer>();
for(int i=2;i<n;i++){

}
return fib;
}

public static void main(String[] args){
Fibonacci f=new Fibonacci();
System.out.println(f.generateFibonacci(13));

}

}

Comment hidden because of low score. Click to expand.
0

I take that back, badal. I do apologize. You code is not recursive, and it does help show a dynamic programming kind of approach (but not really dynamic programming).

Comment hidden because of low score. Click to expand.
0

And here is a dynamic programming kind of approach.

(In C# like code)

``````public static Fibonacci {
private static Dictionary<long, long> _fibonacci;

static Fibonacci() {
_fibonacci = new Dictionary<long, long>();
_fibonacci = 0;
_fibonacci = 1;
}

// Gets the n'th fibonacci number.
public static long Get(long n) {

if (n <= 0} {
throw new InvalidArgumentException("-ve");
}

long value;
if (_fibonacci.TryGetvalue(n, out value)) {
return value;
}

return Get(n-1) + Get(n-2);
}
}``````

Comment hidden because of low score. Click to expand.
0

That must be n < 0, not n <= 0.

Comment hidden because of low score. Click to expand.
0
of 2 vote

int fib(int f) {
if ( f = 1 || f == 2 ) return 1;
else return (fib(f-2)+(f-1));
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

int fib(int f) {
if ( f == 1 || f == 2 ) return 1;
else return ( fib(f-2)+fib(f-1) );
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

This is O(log n) time algorithm.

Comment hidden because of low score. Click to expand.
0
of 0 vote

int Fibonacci(int f)
{
int n = 1;
int nminus = 0;
for (int i = 0; i <= f - 2; i++)
{
int nhold = nminus;
nminus = n;
n = n + nhold;
}
return n;
}

Recursion is nice and all but will quickly bog down with large f numbers...

for the sequence simply change the return type and do a list...

IEnumerable<int> Fib(int f)
{
int n = 1;
int nminus = 0;
for (int i = 0; i <= f - 2; i++)
{
int nhold = nminus;
nminus = n;
n = n + nhold;
yield return n;
}
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

Here's Python:

``````def fib():
a0,a1 = 0,1
while 1:
yield a0
a0,a1 = a1,a0+a1

fibber = fib()
print(next(fibber)) # 0
print(next(fibber)) # 1
print(next(fibber)) # 1
print(next(fibber)) # 2
# and so on as many times as you like``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

class Fabonacci
{
public static void main( String [] args)
{
int a = 0;
int b = 1;
System.out.print(" " + a +" ");
System.out.print(" " + b +" ");
for (int i=0;i <=10; i++)
{
int c = a+b;
System.out.print(" " + c +" ");
b=c;
a=b-a;
}
}
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

Fibonacci series is based on the distribution of chloroplasts. When they divide, they are of opposite charge. The same in java can be done as below. The benefit of the following code is that it doesnt require additional sysouts.

``````class Fibo {
public static void main(String[] args) {
int a = -1, b = 1, c = 0;
for(int count=0; count < 10; count++) {
c = a + b;
System.out.println(c);
a = b;
b = c;
}
}
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.