GeeksforGeeks » C/C++ Programming Questions
fibonacci series element
(3 posts)-
provide a program which will print nth element in fibonacci series. conditions are
1) O(1) time complexity
2) try to keep the memory consumption minimum
3) n is between 1000 to 10000. ( check for integer overflow) -
One simple way is to preload an array of size 9000. Load all Fibonacci number in the array so that the task to get nth Fibonacci number becomes O(1).
-
when i got the question, thought same :) but then point 3 (integer overflow) becomes a problem, we need to keep them as an array of characters i.e. strings. so effectively it becomes, store a large number of strings efficiently, where the permissible characters are '0' to '9'. Hence trie is my opinion.
Reply
You must log in to post.