Toggle Cases in String

Given a string s, convert each lowercase English letter to uppercase and each uppercase English letter to lowercase. Leave all other characters unchanged. Return the resulting string.

Example 1:

Input: s = "Hello World"

Output: "hELLO wORLD"

Explanation: Letters switch case; the space is unchanged.

Example 2:

Input: s = "aBc123"

Output: "AbC123"

Explanation: Digits remain unchanged.

Now Your Turn!

Pick the correct output for the given input

Input: s = "HELLO"

Output: "hello"

Explanation: Uppercase letters become lowercase.

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() <= 100000
  • Sum of lengths of all strings in one test file <= 100000
  • s contains printable ASCII characters, including spaces.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
string toggleCase(string s) {
// Write your code here
return "";
}
};
 
Test Case

Input:

S