AlgoInsight

DSA problem

Encode and Decode TinyURL

MediumHash TablesPattern: Hash Designtop150AmazonGoogleBloombergUberFacebook

TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk. Design a class to encode a URL and decode a tiny URL.

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 back to the original URL.

Implement the Codec class:

Examples

Example 1
Input: url = "https://leetcode.com/problems/design-tinyurl"
Output: "https://leetcode.com/problems/design-tinyurl"
Explanation: Codec codec = new Codec(); String tiny = codec.encode(url); String original = codec.decode(tiny); original equals the input url. encode produces something like "http://tinyurl.com/0", and decode maps it back to the original long URL.

Constraints

3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.

hash-tablestringdesignhash-function

Browse all DSA problems