Oracle Interview Question for Software Engineer / Developers






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

Python code (Ha! Got you there, smart alec. Python integers are unlimited).

def fib(n):
    if n==1:
        return 1
    if n==2:
        return 1
    a,b = 1,2
    while n > 2:
        a,b = b, a+b
        n = n-1
    return b
   
def main():
    print fib(2000)
   
if __name__ == "__main__":
    main()

output

6835702259575806647045396549170580107055408029365524565407553367798082454408054014954534318953113802726603726769523447478238192192714526677939943338306101405105414819705664090901813637296453767095528104868264704914433529355579148731044685634135487735897954629842516947101494253575869699893400976539545740214819819151952085089538422954565146720383752121972115725761141759114990448978941370030912401573418221496592822626

There is also O(log n) arithmetic operation algo (note, arithmetic operations are not O(1) if integers get unbounded), but was too lazy to code that up.

- Anonymous November 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Of course, there are typos/bugs/off-by-one... so some pie on face. LOL.

- Anonymous November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

4224696333392304878706725602341482782579852840250681098010280137314308584370130707224123599639141511088446087538909603607640194711643596029271983312598737326253555802606991585915229492453904998722256795316982874482472992263901833716778060607011615497886719879858311468870876264597369086722884023654422295243347964480139515349562972087652656069529806499841977448720155612802665404554171717881930324025204312082516817125

- Anonymous November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

it should be a,b=1,1

- Anonymous November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The output mentioned in the answer doesn't seem to be correct

- TheMitraBoy February 09, 2014 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

The following code will do in Java. Perhaps, question is a good eye opener..

import java.math.BigDecimal;

public class Fib_2000 {
	
	public static void main(String[] args)
	{
		BigDecimal value = fib(2000);
		System.out.println(" Fibnocci value " + value);
	}
	
	public static BigDecimal fib(int x)
	{
		BigDecimal a = new BigDecimal(0);
		BigDecimal b = new BigDecimal(1);
		BigDecimal sum = new BigDecimal(0);
		for(int i = x; i >=2; i--)
		{
			sum = a.add(b);
			a = b;
			b = sum;
		}
		
		return sum;
	}

}

- sree.srinu38 December 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

The question probably is more about how you would store a large number and how you would do calculation on it.
I think using a list to represent the number should be used!!
Algo we already know F(n) = F(n-1) + F(n-2)

- Varun November 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

Just curious, how does your solution address the need to COMPUTE the Fibinacci number?

- Daniel November 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
1
of 1 vote

awesome!

- Anonymous November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 votes

Yeah, awesome indeed.

The frustrated user will file a perf bug (this will not complete in their lifetime) instead of the eventual correctness bug (this will give wrong results due to integer overflow).


So you can claim it is slow, but you cannot claim it is wrong! HAHA.

- Anonymous November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

buddy recursion is not effective solutiion to solve fibonacci because same recursion brnch is visited many times.

- confused_banda November 28, 2013 | Flag


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