TinyURL is a URL shortening service. You enter a URL such as https://summonersrift.github.io/blog/linux-large-file-search-ubuntu/ and it returns a short URL such as http://tinyurl.com/R3iAsk.
Leetcode 535 has the same problem.
Design the encode and decode methods for the TinyURL service. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL.
Answer:Encode-1. The main is to get a fixed length (say 6 characters) random string in “0-9A-Za-z”.
Encodde-2. If the entry is already in databse or python dictionary/hasmap, you can use a while loop. until a shortened URL found that doesnt exist in dictionary.
Decode: retrieve the key/last part of url. THen just return the yourmap[shorturl.split(“/”)[-1]].