Interview Question 1: Write a function to find the nth number in a fibonnacci sequence

preview_player
Показать описание
This video explains how to find the nth number in a Fibonacci sequence

*Common Interview Question
Рекомендации по теме
Комментарии
Автор

13:27 - 100% this is not the fib(10000) because you get overflow many times over. fib(10000) is around 1.6 to power of 10000 which is gigantic and no standard integer type can hold its value

ulutiu
Автор

Hi,
Try Below:


Scanner s = new Scanner(System.in);

int n= s.nextInt();

int fibonacci=0, num=1, num2=1;

for(int loop=1;loop<n;loop++)
{
fibonacci=num+num2;
num=num2;
num2=fibonacci;
}

System.out.println(num);

nabeeldinhoo
Автор

Did you ask you for a O(logn) algorithm?

Kevin-oqmq
Автор

I want a program which can process huge numbers like in a short time . This was a part of my assignment and I couldn't figure out how.

puneethc
Автор

1234567890987654321 coordinate this formula into relativity and the sequence might relate some how.

googoo