⌘K
Flycodx

URL Shortener Design

URL Shortener Design

MediumSystem Design100% accepted

Design and simulate a URL shortener service that converts long URLs to short codes and handles redirects.

Approach

Process N CREATE then M LOOKUP operations. Assign each created URL a short code 'S' + 3-digit zero-padded sequence number (S001, S002, ...) in creation order. For each CREATE print its code; for each LOOKUP <code> print the original URL (or NOT_FOUND). First line: N M.

Input

2 1 CREATE https://example.com/very/long/path CREATE https://google.com LOOKUP S001

Output

S001 S002 https://example.com/very/long/path
solution.py
Loading editor...
Test 1
Test 2
Test 3

Press Run to test your custom input, or Submit to judge against all test cases.

Sign in to continue

Create a free account to run code, submit solutions and track progress.

  • Free forever — no credit card
  • 10+ languages with live execution
  • Points, streaks & leaderboards
Auto Save OnLn 1, Col 1Spaces: 4UTF-8LFPython 3