{"id":22513946,"url":"https://github.com/emahtab/decode-ways","last_synced_at":"2026-01-27T11:31:53.410Z","repository":{"id":79525418,"uuid":"256238725","full_name":"eMahtab/decode-ways","owner":"eMahtab","description":"Number of ways to decode ","archived":false,"fork":false,"pushed_at":"2020-04-16T14:37:51.000Z","size":128,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-04T21:59:35.654Z","etag":null,"topics":["dynamic-programming","leetcode","problem-solving"],"latest_commit_sha":null,"homepage":"","language":null,"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":"2020-04-16T14:28:13.000Z","updated_at":"2020-04-16T14:38:46.000Z","dependencies_parsed_at":"2023-05-10T17:00:28.670Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/decode-ways","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/decode-ways","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fdecode-ways","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fdecode-ways/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fdecode-ways/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fdecode-ways/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/decode-ways/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fdecode-ways/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28812389,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T07:41:26.337Z","status":"ssl_error","status_checked_at":"2026-01-27T07:41:08.776Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["dynamic-programming","leetcode","problem-solving"],"created_at":"2024-12-07T03:15:13.402Z","updated_at":"2026-01-27T11:31:53.395Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Decode Ways\n## https://leetcode.com/problems/decode-ways\n\nA message containing letters from A-Z is being encoded to numbers using the following mapping:\n\n'A' -\u003e 1\n'B' -\u003e 2\n...\n'Z' -\u003e 26\n\nGiven a non-empty string containing only digits, determine the total number of ways to decode it.\n```\nExample 1:\n\nInput: \"12\"\nOutput: 2\nExplanation: It could be decoded as \"AB\" (1 2) or \"L\" (12).\n\nExample 2:\n\nInput: \"226\"\nOutput: 3\nExplanation: It could be decoded as \"BZ\" (2 26), \"VF\" (22 6), or \"BBF\" (2 2 6).\n```\n\n## Approach :\n\n![Decode Ways](decode-ways.PNG)\n\n## Implementation : Time =\u003e O(number of characters) , Space =\u003e O(number of characters)\n```java\nclass Solution {\n\n    public int numDecodings(String s) {\n\n        if(s == null || s.length() == 0) {\n            return 0;\n        }\n\n        // DP array to store the subproblem results\n        int[] dp = new int[s.length() + 1];\n        dp[0] = 1;\n        // Ways to decode a string of size 1 is 1. Unless the string is '0'.\n        // '0' doesn't have a single digit decode.\n        dp[1] = s.charAt(0) == '0' ? 0 : 1;\n\n        for(int i = 2; i \u003c dp.length; i += 1) {\n\n            // Check if successful single digit decode is possible.\n            if(s.charAt(i-1) != '0') {\n               dp[i] = dp[i-1];  \n            }\n\n            // Check if successful two digit decode is possible.\n            int twoDigit = Integer.parseInt(s.substring(i-2, i));\n            if(twoDigit \u003e= 10 \u0026\u0026 twoDigit \u003c= 26) {\n                dp[i] += dp[i-2];\n            }\n        }\n        return dp[s.length()];\n\n    }\n}\n```\n\n# References :\n1. https://leetcode.com/articles/decode-ways\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fdecode-ways","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fdecode-ways","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fdecode-ways/lists"}