Convert Sentence

You are given a sentence in the form of a string ‘S’. You have to convert ‘S’ into its equivalent mobile numeric keypad sequence, i.e. print the sequence in such a way that if it is typed on the given keypad, the output should be the string ‘S’. A keypad for the reference is shown below.

Note:

1. There will be only lower case letters.
2. There will not be any special characters or capital letters in the input string.
3. There will be no spaces in the string.

Input Format:

The first line of the input contains an integer T denoting the number of test cases.
The first line of each test case contains one integer N, denoting the length of the string ‘S’.
The second line of each test case contains the input string ‘S’.

Output Format:

The only line of output of each test case consists of an output string, denoting the pattern which is required to print ‘S’. 
The output of each test case will be printed in a separate line.

Note:

You do not need to print anything, it has already been taken care of. Just implement the given function.

Constraints:

1 <= T <= 5
1 <= N <= 3000

Where 'T' is the number of test cases and ' N' is the length of the sentence 'S'.
CodingNinjas
author
2y

Approach :

1) For each character, we can store what should be typed on the keypad. We can store this information in a string array named ‘freq’.

2) The size of freq[] will be 26 and index 0 will store t...read more

CodingNinjas
author
2y
Implementation
  • The simplest possible approach is to write how many times we have to press a particular key to get a character.
  • For each character, we can store what should be typed on the keypad. We ca...read more
Help your peers!
Add answer anonymously...
UST Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter