update
parent
ca677e0701
commit
4a02c5d0f1
|
@ -130,7 +130,7 @@ To generate the unique url, we could:
|
|||
* Base 64 is another popular encoding but provides issues for urls because of the additional `+` and `/` characters
|
||||
* The following [Base 62 pseudocode](http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener) runs in O(k) time where k is the number of digits = 7:
|
||||
|
||||
```
|
||||
```python
|
||||
def base_encode(num, base=62):
|
||||
digits = []
|
||||
while num > 0
|
||||
|
@ -142,13 +142,13 @@ def base_encode(num, base=62):
|
|||
|
||||
* Take the first 7 characters of the output, which results in 62^7 possible values and should be sufficient to handle our constraint of 360 million shortlinks in 3 years:
|
||||
|
||||
```
|
||||
```python
|
||||
url = base_encode(md5(ip_address+timestamp))[:URL_LENGTH]
|
||||
```
|
||||
|
||||
We'll use a public [**REST API**](https://github.com/donnemartin/system-design-primer#representational-state-transfer-rest):
|
||||
|
||||
```shell
|
||||
```
|
||||
$ curl -X POST --data '{ "expiration_length_in_minutes": "60", \
|
||||
"paste_contents": "Hello World!" }' https://pastebin.com/api/v1/paste
|
||||
```
|
||||
|
@ -182,8 +182,8 @@ Response:
|
|||
|
||||
```
|
||||
{
|
||||
"paste_contents": "Hello World",
|
||||
"created_at": "YYYY-MM-DD HH:MM:SS",
|
||||
"paste_contents": "Hello World"
|
||||
"created_at": "YYYY-MM-DD HH:MM:SS"
|
||||
"expiration_length_in_minutes": "60"
|
||||
}
|
||||
```
|
||||
|
@ -194,7 +194,7 @@ Since realtime analytics are not a requirement, we could simply **MapReduce** th
|
|||
|
||||
**Clarify with your interviewer how much code you are expected to write**.
|
||||
|
||||
```
|
||||
```python
|
||||
class HitCounts(MRJob):
|
||||
|
||||
def extract_url(self, line):
|
||||
|
|
Loading…
Reference in New Issue