sWAP cASE

  • + 0 comments

    Built-in Function Solutions:

    Time Complexity : O(n) - s.swapcase() iterates through each character in the string s

    Space Complexity: O(n) s.swapcase() returns a new string with the case of each letter swapped.

    Strings in Python are immutable, so a new string of the same length is created in memory.

    📌 Why? A new string of size n is returned → linear space → O(n)

    def swap_case(s):
    
        
        return s.swapcase()
     
    
    if __name__ == '__main__':
        s = input()
        result = swap_case(s)
        print(result)