{"id":"8648509a-e129-49ca-814f-6a5e50a27568","name":"Count Encodings","description":"1. You are given a string str of digits. (will never start with a 0)\r\n2. You are required to encode the str as per following rules\r\n 1 -> a\r\n 2 -> b\r\n 3 -> c\r\n ..\r\n 25 -> y\r\n 26 -> z\r\n3. You are required to calculate and print the count of encodings for the string str.\r\n\r\n For 123 -> there are 3 encodings. abc, aw, lc\r\n For 993 -> there is 1 encoding. iic \r\n For 013 -> This is an invalid input. A string starting with 0 will not be passed.\r\n For 103 -> there is 1 encoding. jc\r\n For 303 -> there are 0 encodings. But such a string maybe passed. In this case \r\n print 0.","inputFormat":"A string str","outputFormat":"count of encodings","constraints":"0 < str.length <= 10","sampleCode":{"cpp":{"code":"#"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n}"},"python":{"code":"p"}},"points":10,"difficulty":"easy","sampleInput":"123","sampleOutput":"3","questionVideo":"https://www.youtube.com/embed/jFZmBQ569So?end=51","hints":[],"associated":[{"id":"037931fc-3adf-4364-b176-bbbb89d5eef8","name":"What will be the encodings if there is two ocnsequitive zero's in the string ?","slug":"what-will-be-the-encodings-if-there-is-two-ocnsequitive-zero-s-in-the-string","type":4},{"id":"7b39158c-d98d-43a6-a311-adeff9442303","name":"What should be in dp[0] and dp[1]?","slug":"what-should-be-in-dp-0-and-dp-1","type":4},{"id":"80a4085d-756d-474d-85c5-10a7025fd83c","name":"While creating dp if previous character is '0' dp[i] will be dependent on","slug":"while-creating-dp-if-previous-character-is-0-dp-i-will-be-dependent-on","type":4},{"id":"ca4af1e3-c904-4837-8f1f-7347fbb05143","name":"While creating dp if current character is '0' dp[i] will be dependent on","slug":"while-creating-dp-if-current-character-is-0-dp-i-will-be-dependent-on","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"3fb0be04-4d86-4979-bd13-732ce6e2ae96","name":"Count Encodings","slug":"count-encodings","type":1}],"next":{"id":"8b497db1-7cd2-4f42-95ef-335dd6133381","name":"Count Encodings","type":3,"slug":"count-encodings"},"prev":{"id":"974bb76f-ae90-4a6b-98af-bc53d3efc274","name":"Arrange Buildings","type":3,"slug":"arrange-buildings"}}}

Count Encodings

1. You are given a string str of digits. (will never start with a 0) 2. You are required to encode the str as per following rules 1 -> a 2 -> b 3 -> c .. 25 -> y 26 -> z 3. You are required to calculate and print the count of encodings for the string str. For 123 -> there are 3 encodings. abc, aw, lc For 993 -> there is 1 encoding. iic For 013 -> This is an invalid input. A string starting with 0 will not be passed. For 103 -> there is 1 encoding. jc For 303 -> there are 0 encodings. But such a string maybe passed. In this case print 0.

{"id":"8648509a-e129-49ca-814f-6a5e50a27568","name":"Count Encodings","description":"1. You are given a string str of digits. (will never start with a 0)\r\n2. You are required to encode the str as per following rules\r\n 1 -> a\r\n 2 -> b\r\n 3 -> c\r\n ..\r\n 25 -> y\r\n 26 -> z\r\n3. You are required to calculate and print the count of encodings for the string str.\r\n\r\n For 123 -> there are 3 encodings. abc, aw, lc\r\n For 993 -> there is 1 encoding. iic \r\n For 013 -> This is an invalid input. A string starting with 0 will not be passed.\r\n For 103 -> there is 1 encoding. jc\r\n For 303 -> there are 0 encodings. But such a string maybe passed. In this case \r\n print 0.","inputFormat":"A string str","outputFormat":"count of encodings","constraints":"0 < str.length <= 10","sampleCode":{"cpp":{"code":"#"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n}"},"python":{"code":"p"}},"points":10,"difficulty":"easy","sampleInput":"123","sampleOutput":"3","questionVideo":"https://www.youtube.com/embed/jFZmBQ569So?end=51","hints":[],"associated":[{"id":"037931fc-3adf-4364-b176-bbbb89d5eef8","name":"What will be the encodings if there is two ocnsequitive zero's in the string ?","slug":"what-will-be-the-encodings-if-there-is-two-ocnsequitive-zero-s-in-the-string","type":4},{"id":"7b39158c-d98d-43a6-a311-adeff9442303","name":"What should be in dp[0] and dp[1]?","slug":"what-should-be-in-dp-0-and-dp-1","type":4},{"id":"80a4085d-756d-474d-85c5-10a7025fd83c","name":"While creating dp if previous character is '0' dp[i] will be dependent on","slug":"while-creating-dp-if-previous-character-is-0-dp-i-will-be-dependent-on","type":4},{"id":"ca4af1e3-c904-4837-8f1f-7347fbb05143","name":"While creating dp if current character is '0' dp[i] will be dependent on","slug":"while-creating-dp-if-current-character-is-0-dp-i-will-be-dependent-on","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"3fb0be04-4d86-4979-bd13-732ce6e2ae96","name":"Count Encodings","slug":"count-encodings","type":1}],"next":{"id":"8b497db1-7cd2-4f42-95ef-335dd6133381","name":"Count Encodings","type":3,"slug":"count-encodings"},"prev":{"id":"974bb76f-ae90-4a6b-98af-bc53d3efc274","name":"Arrange Buildings","type":3,"slug":"arrange-buildings"}}}
plane

Editor


Loading...

Count Encodings

easy

1. You are given a string str of digits. (will never start with a 0) 2. You are required to encode the str as per following rules 1 -> a 2 -> b 3 -> c .. 25 -> y 26 -> z 3. You are required to calculate and print the count of encodings for the string str. For 123 -> there are 3 encodings. abc, aw, lc For 993 -> there is 1 encoding. iic For 013 -> This is an invalid input. A string starting with 0 will not be passed. For 103 -> there is 1 encoding. jc For 303 -> there are 0 encodings. But such a string maybe passed. In this case print 0.

Constraints

0 < str.length <= 10

Format

Input

A string str

Output

count of encodings

Example

Sample Input

123

Sample Output

3

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode