VOOZH about

URL: https://www.geeksforgeeks.org/dsa/convert-sentence-equivalent-mobile-numeric-keypad-sequence/

⇱ Convert a sentence into its equivalent mobile numeric keypad sequence - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Convert a sentence into its equivalent mobile numeric keypad sequence

Last Updated : 18 Jan, 2024

Given a sentence in the form of a string, convert it into its equivalent mobile numeric keypad sequence. 

👁 Mobile-keypad

Examples :

Input: GEEKSFORGEEKS
Output: 4333355777733366677743333557777
Explanation: For obtaining a number, we need to press a number corresponding to that character for a number of times equal to the position of the character. For example, for character E, press number 3 two times and accordingly.

Input : HELLO WORLD
Output : 4433555555666096667775553

Approach: 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 : 


Output
4333355777733366677743333557777

Time complexity: O(N), For traversing the string
Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: