{"id":22513958,"url":"https://github.com/emahtab/climbing-stairs","last_synced_at":"2026-08-12T07:38:02.128Z","repository":{"id":79525351,"uuid":"229369397","full_name":"eMahtab/climbing-stairs","owner":"eMahtab","description":"Climbing Stairs","archived":false,"fork":false,"pushed_at":"2020-01-16T09:17:19.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-05T00:59:41.715Z","etag":null,"topics":["climbing-stairs","dynamic-programming","leetcode","problem-solving"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-21T03:11:10.000Z","updated_at":"2020-06-07T13:53:58.000Z","dependencies_parsed_at":"2023-05-10T17:00:44.498Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/climbing-stairs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/climbing-stairs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fclimbing-stairs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fclimbing-stairs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fclimbing-stairs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fclimbing-stairs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/climbing-stairs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fclimbing-stairs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":36555399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-08-06T04:43:03.162Z","status":"online","status_checked_at":"2026-08-12T02:00:07.134Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["climbing-stairs","dynamic-programming","leetcode","problem-solving"],"created_at":"2024-12-07T03:15:17.181Z","updated_at":"2026-08-12T07:38:02.091Z","avatar_url":"https://github.com/eMahtab.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Climbing Stairs\n\nYou are climbing a stair case. It takes n steps to reach to the top.\nEach time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?\n\nNote: Given n will be a positive integer.\n\n```\n\nExample 1:\n\nInput: 2\nOutput: 2\nExplanation: There are two ways to climb to the top.\n1. 1 step + 1 step\n2. 2 steps\n\n\nExample 2:\n\nInput: 3\nOutput: 3\nExplanation: There are three ways to climb to the top.\n1. 1 step + 1 step + 1 step\n2. 1 step + 2 steps\n3. 2 steps + 1 step\n```\n### Implementation :\n\n#### Dynamic Programming\n```java\npublic class App {\n\t\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"Total ways to climb 3 stairs: \"+climbStairs(3));\n\t}\n\t\n\t// Runtime = O(n) , Space = O(n)\n\tprivate static  int climbStairs(int n) {\n         int[] dpTable = new int[n+1];\n         dpTable[0] = 1;\n         dpTable[1] = 1;\n         for(int i = 2; i \u003c= n; i++){\n             dpTable[i] = dpTable[i-1] + dpTable[i-2];\n         }\n         return dpTable[n];\n      }\n}\n\n```\n\nThe above implementation have both runtime and space complexity of O(n)\n```\nRuntime Complexity = O(n)\nSpace Complexity   = O(n)\n```\n\n#### Dynamic Programming - Space Optimization O(1)\n```java\npublic class App {\n\t\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"Total ways to climb 3 stairs: \"+climbStairs(3));\n\t}\n\t\n\t// Runtime = O(n) , Space = O(1)\n\tprivate static  int climbStairs(int n) {\n\t     int oneStairBefore = 1;\n             int twoStairsBefore = 1;\n             int nthStair = 1;\n\t     for(int i = 2; i \u003c= n; i++){\n\t\t  nthStair = oneStairBefore +  twoStairsBefore;\n\t\t  twoStairsBefore =  oneStairBefore;\n\t\t  oneStairBefore = nthStair;\n\t     }\n           return nthStair;\n        }\n}\n```\n\nThe above implementation have runtime complexity of O(n) and space complexity of O(1)\n```\nRuntime Complexity = O(n)\nSpace Complexity   = O(1)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fclimbing-stairs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fclimbing-stairs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fclimbing-stairs/lists"}