{ "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\n

The fibonacci sequence is defined by the relation Xn = Xn-1 + Xn-2.

\n\n

The first few numbers of the series are 0, 1, 1, 2, 3, 5, 8, 13.

\n\n

 

\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\n\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Easy", "likes": 222, "dislikes": 25, "isLiked": null, "similarQuestions": "[{\"title\": \"Nested Array Generator\", \"titleSlug\": \"nested-array-generator\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Design Cancellable Function\", \"titleSlug\": \"design-cancellable-function\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]", "exampleTestcases": "5\n0", "categoryTitle": "JavaScript", "contributors": [], "topicTags": [], "companyTagStats": null, "codeSnippets": [ { "lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @return {Generator}\n */\nvar fibGenerator = function*() {\n \n};\n\n/**\n * const gen = fibGenerator();\n * gen.next().value; // 0\n * gen.next().value; // 1\n */", "__typename": "CodeSnippetNode" }, { "lang": "TypeScript", "langSlug": "typescript", "code": "function* fibGenerator(): Generator {\n\t\n};\n\n/**\n * const gen = fibGenerator();\n * gen.next().value; // 0\n * gen.next().value; // 1\n */", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"19.3K\", \"totalSubmission\": \"23.3K\", \"totalAcceptedRaw\": 19300, \"totalSubmissionRaw\": 23289, \"acRate\": \"82.9%\"}", "hints": [ "Javascript has the concept of generators. They are critical to this problem.", "First yield 0 and 1.", "Create an infinite \"while(true)\" loop.", "In that loop, continuously yield the next value which is the sum of the previous two." ], "solution": { "id": "1932", "canSeeDetail": true, "paidOnly": false, "hasVideoSolution": false, "paidOnlyVideo": true, "__typename": "ArticleNode" }, "status": null, "sampleTestCase": "5", "metaData": "{\n \"name\": \"fibGenerator\",\n \"params\": [\n {\n \"name\": \"callCount\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"integer[]\"\n },\n \"languages\": [\n \"typescript\",\n \"javascript\"\n ],\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [], "enableRunCode": true, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"javascript\": [\"JavaScript\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For 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.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2022 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }