HUAWEI TECHNOLOGIES Hiring | On Campus OA (2024) | Encode and Decode TinyURL
Question · Posted Jun 2026
Problem Statement Design a URL shortening service similar to TinyURL. Implement a class that supports the following operations: encode(longUrl) Takes a long URL as input. Generates a unique shortened URL. Returns the shortened URL. decode(shortUrl) Takes a shortened URL as input. Returns the original URL associated with it. The same long URL should always map to the same short URL during the lifetime of the service. Example Input encode("https://leetcode.com/problems/design-tinyurl") decode("http://tinyurl.com/abc123") Output "http://tinyurl.com/abc123" "https://leetcode.com/problems/design-tinyurl" Sample Execution Input: longUrl = "https://leetcode.com/problems/design-tinyurl" Output: ...
The full answer & interview discussion are available to premium members.
Log in Create a free account