Amazon Interview Question for Software Engineer / Developers






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

it depends how what kind of optimization you want.
If optimization of speed, use caching.
If optimization of memory, just try this:

int first = 0;
int second = 1;
for (int i = 3;i <= n;i ++){
 second = first + second;
 first = second - first;
}
cout << second << endl;
}

- Anonymous February 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The above code is wrong btw. what if n = 3

- Ani February 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote
write two functions...than it wud be possible assuming series is: 0 1 1 2 3 5 8....... {{{ fib(int n) { return n==1?0:fib2(n,0,1) } fib2(int n,int a, int b) { return n==1?a:fib2(n-1,b,a+b); } wud work 1: 1 0 1---->0 2: 2 0 1 1 1 1---->1 3: 3 0 1 2 1 1 1 1 2--->1 4: 4 0 1 3 1 1 2 1 2 1 2 3---->2 5: 5 0 1 4 1 1 3 1 2 2 2 3 1 3 5--->3 and so on - utscool@gmail February 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
write two functions...than it wud be possible assuming series is: 0 1 1 2 3 5 8....... {{{ fib(int n) { return n==1?0:fib2(n,0,1) } fib2(int n,int a, int b) { return n==1?a:fib2(n-1,b,a+b); } wud work 1: 1 0 1---->0 2: 2 0 1 1 1 1---->1 3: 3 0 1 2 1 1 1 1 2--->1 4: 4 0 1 3 1 1 2 1 2 1 2 3---->2 5: 5 0 1 4 1 1 3 1 2 2 2 3 1 3 5--->3 and so on - utscool@gmail February 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

f=0 s=1
print "f"
print "s"
while (counter>0)
{
f=s+f
s=f-s
print "f"
}

- clrs March 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

inside loop counter--

- clrs March 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

check this link, it has a log n approach:

ics.uci.edu/~eppstein/161/960109.html

- fragzilla March 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Amazing! are u sure interviewer will understand the solution??

- Anonymous March 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

A non recursive solution saving current & previous OR us an array to save fib. no. calculated so far. Both solutions are example of dynamic programming but second uses O(n) time

- M August 08, 2010 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More