You are viewing a single comment's thread. Return to all 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)
Seems like cookies are disabled on this browser, please enable them to open this website
sWAP cASE
You are viewing a single comment's thread. Return to all 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)