Build a URL Shortener
Create a URL shortening service like bit.ly with analytics and custom domains.
Problem Statement
Build a complete URL shortening service that includes:
1. **URL Shortening**: Convert long URLs into short, shareable links
2. **Custom Aliases**: Allow users to create custom short URLs
3. **Analytics**: Track clicks, referrers, and geographic data
4. **Expiration**: Support URL expiration dates
5. **API**: RESTful API for programmatic access
**Requirements:**
- Handle invalid URLs gracefully
- Prevent duplicate short URLs
- Implement rate limiting
- Store analytics data
- Support bulk URL creation
**Technical Specifications:**
- Use a database to store URLs and analytics
- Implement proper error handling
- Add input validation and sanitization
- Include unit tests
- Document your API endpoints
Examples
Input:
POST /api/shorten
{"url": "https://www.example.com/very/long/url", "custom_alias": "mylink"}
Output:
{"short_url": "https://short.ly/mylink", "original_url": "https://www.example.com/very/long/url", "clicks": 0}
Explanation:
API should return the shortened URL with metadata
Community Discussion
Solution approach
Here's how I solved this challenge: 1. First, I analyzed the problem 2. Then I implemented the solution 3. Finally, I optimized it Hope this helps!
Optimization tips
You can optimize this solution by using a hash map instead of nested loops. This reduces time complexity from O(n²) to O(n).
Optimization tips
You can optimize this solution by using a hash map instead of nested loops. This reduces time complexity from O(n²) to O(n).
Edge case question
What happens when the input is empty? Should we handle this case?
Quick Actions
Challenge Statistics
Supported Languages
Tags
Community Discussion
Solution approach
Here's how I solved this challenge: 1. First, I analyzed the problem 2. Then I implemented the solution 3. Finally, I optimized it Hope this helps!
Optimization tips
You can optimize this solution by using a hash map instead of nested loops. This reduces time complexity from O(n²) to O(n).
Optimization tips
You can optimize this solution by using a hash map instead of nested loops. This reduces time complexity from O(n²) to O(n).
Edge case question
What happens when the input is empty? Should we handle this case?