Given a sentence in the form of a string, convert it into its equivalent mobile numeric keypad sequence.
Input : GEEKSFORGEEKS Output : 4333355777733366677743333557777 For obtaining a number, we need to press a number corresponding to that character for number of times equal to position of the character. For example, for character C, we press number 2 three times and accordingly. Input : HELLO WORLD Output : 4433555555666096667775553
Follow the steps given below to convert a sentence into its equivalent mobile numeric keypad sequence.
- For each character, store the sequence which should be obtained at its respective position in an array, i.e. for Z, store 9999. For Y, store 999. For K, store 55 and so on.
- For each character, subtract ASCII value of ‘A’ and obtain the position in the array pointed
by that character and add the sequence stored in that array to a string.
- If the character is a space, store 0
- Print the overall sequence.
Below is the implementation of above method :
Time complexity : O(n)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Mobile Numeric Keypad Problem
- Convert the ASCII value sentence to its equivalent string
- Count of buttons pressed in a keypad mobile
- Print given sentence into its equivalent ASCII form
- Convert an unbalanced bracket sequence to a balanced sequence
- Convert String into Binary Sequence
- Frequency of smallest character in first sentence less than that of second sentence
- Check whether the string can be printed using same row of qwerty keypad
- Check whether two strings are equivalent or not according to given condition
- Maximize the decimal equivalent by flipping only a contiguous set of 0s
- Minimum operations required to transform a sequence of numbers to a sequence where a[i]=a[i+2]
- Count of substrings whose Decimal equivalent is greater than or equal to K
- Check whether the binary equivalent of a number ends with given string or not
- k-th missing element in increasing sequence which is not present in a given sequence
- Check if a given mobile number is fancy
- Splitting a Numeric String
- Count number of substrings with numeric value greater than X
- Extract maximum numeric value from a given string | Set 2 (Regex approach)
- Split numeric, alphabetic and special symbols from a String
- Minimum Cost to make two Numeric Strings Identical
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : chitranayal