`{"id":"d1b203b5-c621-4678-ba30-4a217df14b4a","name":"Get Kpc","description":"1. You are given a string str. The string str will contains numbers only, where each number stands for a key pressed on a mobile phone.\r\n2. The following list is the key to characters map :\r\n 0 -> .;\r\n 1 -> abc\r\n 2 -> def\r\n 3 -> ghi\r\n 4 -> jkl\r\n 5 -> mno\r\n 6 -> pqrs\r\n 7 -> tu\r\n 8 -> vwx\r\n 9 -> yz\r\n3. Complete the body of getKPC function - without changing signature - to get the list of all words that could be produced by the keys in str.\r\nUse sample input and output to take idea about output.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you. ","inputFormat":"A string str\r\n","outputFormat":"Contents of the arraylist containing words as shown in sample output\r\n","constraints":"0 &lt;= str.length &lt;= 10\r\nstr contains numbers only\r\n","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<string>\n#include<vector>\nusing namespace std;\n\nvector<string> getKPC(string s){\n //Write your code here\n}\n\n\nint main(){\n string s;\n cin >> s;\n vector<string> ans = getKPC(s);\n int cnt = 0;\n\n cout << '[';\n for (string str : ans){\n if (cnt != ans.size() - 1)\n cout << str << \", \";\n else\n cout << str;\n cnt++;\n }\n cout << ']';\n}"},"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\r\n public static ArrayList<String> getKPC(String str) {\r\n return null;\r\n }\r\n\r\n}"},"python":{"code":"s = input()\n\ndef getKPC(s):\n #Write your code here\n \nans = getKPC(s)\n\nprint(\"[\"+', '.join(ans) + \"]\")"}},"points":10,"difficulty":"easy","sampleInput":"78","sampleOutput":"[tv, tw, tx, uv, uw, ux]","questionVideo":"https://www.youtube.com/embed/97mF4juql6g","hints":[],"associated":[],"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":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"7ee3430b-142e-440c-a2dc-48fa1bd45896","name":"Get Kpc","slug":"get-kpc","type":1}],"next":{"id":"c32c9630-ef86-4440-ba9e-9c3488c293f3","name":"Get Kpc","type":3,"slug":"get-kpc"},"prev":{"id":"a3882bca-cf16-477e-b2c6-fa4b4b824259","name":"Get Subsequence","type":3,"slug":"get-subsequence"}}}`

# Get Kpc

1. You are given a string str. The string str will contains numbers only, where each number stands for a key pressed on a mobile phone. 2. The following list is the key to characters map : 0 -> .; 1 -> abc 2 -> def 3 -> ghi 4 -> jkl 5 -> mno 6 -> pqrs 7 -> tu 8 -> vwx 9 -> yz 3. Complete the body of getKPC function - without changing signature - to get the list of all words that could be produced by the keys in str. Use sample input and output to take idea about output. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

`{"id":"d1b203b5-c621-4678-ba30-4a217df14b4a","name":"Get Kpc","description":"1. You are given a string str. The string str will contains numbers only, where each number stands for a key pressed on a mobile phone.\r\n2. The following list is the key to characters map :\r\n 0 -> .;\r\n 1 -> abc\r\n 2 -> def\r\n 3 -> ghi\r\n 4 -> jkl\r\n 5 -> mno\r\n 6 -> pqrs\r\n 7 -> tu\r\n 8 -> vwx\r\n 9 -> yz\r\n3. Complete the body of getKPC function - without changing signature - to get the list of all words that could be produced by the keys in str.\r\nUse sample input and output to take idea about output.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you. ","inputFormat":"A string str\r\n","outputFormat":"Contents of the arraylist containing words as shown in sample output\r\n","constraints":"0 &lt;= str.length &lt;= 10\r\nstr contains numbers only\r\n","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<string>\n#include<vector>\nusing namespace std;\n\nvector<string> getKPC(string s){\n //Write your code here\n}\n\n\nint main(){\n string s;\n cin >> s;\n vector<string> ans = getKPC(s);\n int cnt = 0;\n\n cout << '[';\n for (string str : ans){\n if (cnt != ans.size() - 1)\n cout << str << \", \";\n else\n cout << str;\n cnt++;\n }\n cout << ']';\n}"},"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\r\n public static ArrayList<String> getKPC(String str) {\r\n return null;\r\n }\r\n\r\n}"},"python":{"code":"s = input()\n\ndef getKPC(s):\n #Write your code here\n \nans = getKPC(s)\n\nprint(\"[\"+', '.join(ans) + \"]\")"}},"points":10,"difficulty":"easy","sampleInput":"78","sampleOutput":"[tv, tw, tx, uv, uw, ux]","questionVideo":"https://www.youtube.com/embed/97mF4juql6g","hints":[],"associated":[],"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":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"7ee3430b-142e-440c-a2dc-48fa1bd45896","name":"Get Kpc","slug":"get-kpc","type":1}],"next":{"id":"c32c9630-ef86-4440-ba9e-9c3488c293f3","name":"Get Kpc","type":3,"slug":"get-kpc"},"prev":{"id":"a3882bca-cf16-477e-b2c6-fa4b4b824259","name":"Get Subsequence","type":3,"slug":"get-subsequence"}}}`

Editor

# Get Kpc

easy

1. You are given a string str. The string str will contains numbers only, where each number stands for a key pressed on a mobile phone. 2. The following list is the key to characters map : 0 -> .; 1 -> abc 2 -> def 3 -> ghi 4 -> jkl 5 -> mno 6 -> pqrs 7 -> tu 8 -> vwx 9 -> yz 3. Complete the body of getKPC function - without changing signature - to get the list of all words that could be produced by the keys in str. Use sample input and output to take idea about output. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

## Constraints

0 <= str.length <= 10 str contains numbers only

## Format

A string str

### Output

Contents of the arraylist containing words as shown in sample output

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}78`

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}[tv, tw, tx, uv, uw, ux]`

Question Video

Discussions

Show Discussion

Related Resources