Python: Translation

Thought Process

The problem requires checking if the second string 'tWord' is the reverse of the first string 'sWord'. To solve this, we reverse 'sWord' and compare it with 'tWord'. If they match, we output "YES"; otherwise, we output "NO". This approach ensures that we correctly determine if 'tWord' is the reverse of 'sWord'.

def main():
    sWord = input().strip()
    tWord = input().strip()

    print("YES" if sWord[::-1] == tWord else "NO")

if __name__ == "__main__":
    main()

Code Complexity

Time Complexity: O(n)

The algorithm reverses the string and compares it, both of which take linear time relative to the length of the string.

Space Complexity: O(n)

The algorithm creates a reversed copy of the string, which takes extra space proportional to the length of the string.

Code copied!