Encode and Decode TinyURL - Leetcode 535 - Python

preview_player
Показать описание


0:00 - Read the problem
1:25 - Drawing Explanation
4:55 - Coding Explanation

leetcode 535

#sorted #array #python
Рекомендации по теме
Комментарии
Автор

i'm a fan of your channel. a small typo i see on line 11: len(encodeMap) -> len(self.encodeMap)

harryz
Автор

This problem is often encountered at work, I usually use the md5 encryption key to store in a global cache. this example uses a hash map, very similar.

sidazhong
Автор

this is good. but your solution can be optimized, because you work with digits so you have 0-9 and then you move to the bext digit (from 9 you move to 10 from 99 you move to 100 etc...) you can choose different base than decimal such as HEX (base 16 so you have 0-9 and A-F to use) or even better base which is base 64. so your code just needs to convert that serial number to base 16 or base 64 and you get a more optimized

yaronnir
Автор

How about we save only the part after base in the hashTable to reduce space complexity?

forentrepreneurs
Автор

Why did you add 1 to the length of longUrl? URLs can't end with 0 or are there other reasons?

keshav
Автор

Or just have the decode map and make a new entry every time you encode. How is this medium?

RemotHuman
Автор

I don't know. I thought this was looking for something like a Hoffman Encoding that you are creating a bit stream to actually encode a message. This feels like a cheat.

jkrigelman
Автор

With this approach, wouldn't we have a collision in the "shortUrl" map if we passed in 2 url's with the same length?

ajmalaboobacker
Автор

Why did you add 1 to the length of longUrl?

tonyz
Автор

hi which language did you use in the google coding interview, was it Python

Abhishek-tvpx
Автор

how your getting this power of 10
i don't understand this

vidhanrathore
Автор

we dont need encoded map. having just the decoded map is sufficient.

bppreuu
Автор

You are not actually shortening the URL. This is some kind of a trick. You could then actually do a better one like this then:

def encode(self, longUrl: str) -> str:
return longUrl


def decode(self, shortUrl: str) -> str:
return shortUrl

AashishM
Автор

str(len(self.encodeMap) + 1)

We need to add self

Ankit-hsnb