From a600b1b376b499c70b9ca29f0cb37ef1315332cf Mon Sep 17 00:00:00 2001 From: Gajay <6947656+GAjay@users.noreply.github.com> Date: Sun, 25 Oct 2026 01:30:33 +0000 Subject: [PATCH] feat(daily): implement 2026-10-25 climb-stairs --- automation/state.json | 4 +-- problems/2026-10-25-climb-stairs/README.md | 25 +++++++++++++++++++ .../climb-stairs.test.js | 17 +++++++++++++ problems/2026-10-25-climb-stairs/solution.js | 15 +++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 problems/2026-10-25-climb-stairs/README.md create mode 100644 problems/2026-10-25-climb-stairs/climb-stairs.test.js create mode 100644 problems/2026-10-25-climb-stairs/solution.js diff --git a/automation/state.json b/automation/state.json index e86eea9..5102c83 100644 --- a/automation/state.json +++ b/automation/state.json @@ -1,4 +1,4 @@ { - "catalogIndex": 4, - "lastRunDate": "2026-10-24" + "catalogIndex": 5, + "lastRunDate": "2026-10-25" } diff --git a/problems/2026-10-25-climb-stairs/README.md b/problems/2026-10-25-climb-stairs/README.md new file mode 100644 index 0000000..33f55cb --- /dev/null +++ b/problems/2026-10-25-climb-stairs/README.md @@ -0,0 +1,25 @@ +# Climbing Stairs + +## Problem + +You are climbing a staircase. It takes `n` steps to reach the top. + +Each time you can climb `1` or `2` steps. In how many distinct ways can you climb to the top? + +## Examples + +``` +Input: n = 2 +Output: 2 + +Input: n = 3 +Output: 3 +``` + +## Constraints + +- `1 <= n <= 45` + +## Notes + +Implement `climbStairs` in `solution.js`. diff --git a/problems/2026-10-25-climb-stairs/climb-stairs.test.js b/problems/2026-10-25-climb-stairs/climb-stairs.test.js new file mode 100644 index 0000000..5b42385 --- /dev/null +++ b/problems/2026-10-25-climb-stairs/climb-stairs.test.js @@ -0,0 +1,17 @@ +import { describe, it } from "node:test"; +import assert from "node:assert/strict"; +import { climbStairs } from "./solution.js"; + +describe("climbStairs", () => { + it("two steps", () => { + assert.equal(climbStairs(2), 2); + }); + + it("three steps", () => { + assert.equal(climbStairs(3), 3); + }); + + it("one step", () => { + assert.equal(climbStairs(1), 1); + }); +}); diff --git a/problems/2026-10-25-climb-stairs/solution.js b/problems/2026-10-25-climb-stairs/solution.js new file mode 100644 index 0000000..ea97e5f --- /dev/null +++ b/problems/2026-10-25-climb-stairs/solution.js @@ -0,0 +1,15 @@ +/** + * @param {number} n + * @returns {number} + */ +export function climbStairs(n) { + if (n <= 2) return n; + let a = 1; + let b = 2; + for (let i = 3; i <= n; i++) { + const next = a + b; + a = b; + b = next; + } + return b; +}