{ "data": { "question": { "questionId": "2732", "questionFrontendId": "2620", "boundTopicId": null, "title": "Counter", "titleSlug": "counter", "content": "
Given an integer n
, return a counter
function. This counter
function initially returns n
and then returns 1 more than the previous value every subsequent time it is called (n
, n + 1
, n + 2
, etc).
\n
Example 1:
\n\n\nInput: \nn = 10 \n["call","call","call"]\nOutput: [10,11,12]\nExplanation: \ncounter() = 10 // The first time counter() is called, it returns n.\ncounter() = 11 // Returns 1 more than the previous time.\ncounter() = 12 // Returns 1 more than the previous time.\n\n\n
Example 2:
\n\n\nInput: \nn = -2\n["call","call","call","call","call"]\nOutput: [-2,-1,0,1,2]\nExplanation: counter() initially returns -2. Then increases after each sebsequent call.\n\n\n
\n
Constraints:
\n\n-1000 <= n <= 1000
0 <= calls.length <= 1000
calls[i] === "call"
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" } } }