Encode and Decode TinyURL

Problem Summary

(Write in your own words, not copied from LeetCode. This forces comprehension.)

Approach Taken

(Step-by-step logic or pseudocode before coding.)

Main Concepts Used

(Mark the CS concepts or algorithms used.)

Time & Space Complexity

Code

class Codec:
    def __init__(self):
        self.urlMap = {}
        self.base = 'https://tinyurl.com'

    def hash(self, input: str) -> str:
        return len(self.urlMap)

    def encode(self, longUrl: str) -> str:
        """Encodes a URL to a shortened URL."""
        key = self.hash(longUrl)
        tinyUrl = f'{self.base}/{key}'
        self.urlMap[tinyUrl] = longUrl
        return tinyUrl

    def decode(self, shortUrl: str) -> str:
        """Decodes a shortened URL to its original URL."""
        return self.urlMap[shortUrl]

Common Mistakes / Things I Got Stuck On