sWAP cASE HackerRank Solution

The problem at hand involves taking a string as input and returning a new string where the case of each character is swapped. If a character is uppercase, it is converted to lowercase and vice versa. Non-alphabetic characters are left unchanged.

Secure your next interview 🎯

CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷

Here is the sWAP cASE HackerRank Solution HackerRank solution using CodeRankGPT:

The solution works by iterating over each character in the input string. If the character is uppercase, it is converted to lowercase using the 'lower' method. If the character is lowercase, it is converted to uppercase using the 'upper' method. Non-alphabetic characters are simply appended to the new string as they are. The resulting string is then returned.


def swap_case(sentence):
    updated_s = ""
    for c in sentence:
        if c.isupper():
            updated_s += c.lower()
        elif c.islower():
            updated_s += c.upper()
        else:
            updated_s += c
    return updated_s

if __name__ == "__main__":
    s = input()
    result = swap_case(s)
    print(result)

If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.

AI is here now, and other candidates might be using it to get ahead and win the job. 🧐

Built on Unicorn Platform