{ "data": { "question": { "questionId": "2775", "questionFrontendId": "2648", "boundTopicId": null, "title": "Generate Fibonacci Sequence", "titleSlug": "generate-fibonacci-sequence", "content": "
Write a generator function that returns a generator object which yields the fibonacci sequence.
\n\nThe fibonacci sequence is defined by the relation Xn = Xn-1 + Xn-2
.
The first few numbers of the series are 0, 1, 1, 2, 3, 5, 8, 13
.
\n
Example 1:
\n\n\nInput: callCount = 5\nOutput: [0,1,1,2,3]\nExplanation:\nconst gen = fibGenerator();\ngen.next().value; // 0\ngen.next().value; // 1\ngen.next().value; // 1\ngen.next().value; // 2\ngen.next().value; // 3\n\n\n
Example 2:
\n\n\nInput: callCount = 0\nOutput: []\nExplanation: gen.next() is never called so nothing is outputted\n\n\n
\n
Constraints:
\n\n0 <= callCount <= 50
Node.js 16.13.2
.
Your code is run with --harmony
flag, enabling new ES6 features.
lodash.js library is included by default.
\\r\\n\\r\\nFor Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.
\"], \"typescript\": [\"Typescript\", \"TypeScript 5.1.6, Node.js 16.13.2
.
Your code is run with --harmony
flag, enabling new ES2022 features.
lodash.js library is included by default.
\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }