846. Change Every Letter with the Next Lexicographic

You are given a string s.

Write a function to replace every alphabetic character in the string with its next letter in the lexicographical order.

  • 'a' becomes 'b', 'b' becomes 'c', ..., 'y' becomes 'z', and
  • 'z' becomes 'a' (wrap around).
  • Similarly, 'A' becomes 'B', ..., 'Y' becomes 'Z', and 'Z' becomes 'A'.

Non-alphabet characters should remain unchanged.

Example 1:

Input: s = "abcdxyz"

Output: "bcdeyza"

Explanation: Each letter is replaced with the next one. 'z' wraps to 'a'.

Example 2:

Input: s = "Java"

Output: "Kbwb"

Explanation: J→K, a→b, v→w, a→b

Now Your Turn!

Pick the correct output for the given input

Input: s = "Java"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 105
  • s may contain uppercase and lowercase English letters and special characters
0
class Solution {
public:
string shiftCharacters(const string& s) {
// Your code goes here
}
};
Test Case

Input:

S