Encode The String Problem Statement

Given a string S of length N, encode it using the specified rules related to vowels and consonants.

Explanation:

Follow these encoding rules:

  1. If the character is a vowel, change it to the next character in the alphabetical sequence.
  2. If the character is a consonant, change it to the previous character in the alphabetical sequence.
  3. The next character of ‘z’ is ‘a’.
  4. The previous character of ‘a’ is ‘z’.

Input:

The first line contains an integer 'T', which denotes the number of test cases. Each test case consists of: 
The first line with integer ‘N’, the length of the string.
The second line contains a string ‘S’ of length ‘N’.

Output:

The encoded string for each test case on a new line.

Example:

Suppose:

N = 4, S = "code"

Following the encoding rules, the encoded string becomes "bpcf".

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 10^5
  • The sum of all 'N' in all test cases <= 10^5
  • The string 'S' contains only lowercase letters.

Note:

You don’t need to handle the output; just implement the function to return the required encoded string.

Anonymous
10mo
Encode The String You are given a password string P of length N. The password needs to be encoded before storing it to the database. The password string can be encoded using the following rules: 1) If...read more
Help your peers!
Add answer anonymously...
Wipro Project 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

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