Back to DSA sheet
Encode and Decode TinyURL
MediumArraysDesign encode(longUrl) that returns a short URL and decode(shortUrl) that recovers the original. Any consistent reversible scheme works.
Input format (stdin): the first line has q. Each next line is a long URL to encode then immediately decode. For each, print the decoded URL, which must equal the original.
Examples
Input: 2
https://example.com/a
https://example.com/b
Output: https://example.com/a
https://example.com/b
Each URL round-trips through encode/decode unchanged.
Constraints
- 1 <= q <= 10^4
- URLs are valid strings
Sheets
NeetCode 250
encode-and-decode-tinyurl.cpp1 sample tests
Loading editor
Test results
Run the sample tests to check your solution against expected output.
Custom input (stdin)
Output
Run your code to see its output.