Encode and Decode TinyURL - Leetcode 535 - Python

  Рет қаралды 18,967

NeetCode

NeetCode

Күн бұрын

Пікірлер: 25
@harryz7973
@harryz7973 3 жыл бұрын
i'm a fan of your channel. a small typo i see on line 11: len(encodeMap) -> len(self.encodeMap)
@NeetCode
@NeetCode 3 жыл бұрын
Thanks, good catch!
@sidazhong2019
@sidazhong2019 Жыл бұрын
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.
@bigboyshassen59
@bigboyshassen59 2 ай бұрын
sir, you can run into collisions with md5.
@yaronnir
@yaronnir 2 жыл бұрын
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 solution......
@cw5948
@cw5948 11 ай бұрын
He did say characters and digits 4:30
@jkrigelman
@jkrigelman 2 жыл бұрын
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.
@rocky6345
@rocky6345 Жыл бұрын
lol yeah i thought the problem was a lossless compression problem, but also there's no way i implement something like hoffman in an interview
@RemotHuman
@RemotHuman 11 ай бұрын
Or just have the decode map and make a new entry every time you encode. How is this medium?
@forentrepreneurs3852
@forentrepreneurs3852 2 жыл бұрын
How about we save only the part after base in the hashTable to reduce space complexity?
@keshav1530
@keshav1530 3 жыл бұрын
Why did you add 1 to the length of longUrl? URLs can't end with 0 or are there other reasons?
@crisag.2698
@crisag.2698 Жыл бұрын
He added 1 to the length of the encode map, not to the length of the string
@tonyz2203
@tonyz2203 2 жыл бұрын
Why did you add 1 to the length of longUrl?
@tarunshanmugam8905
@tarunshanmugam8905 7 ай бұрын
to start with 1 not zero
@anuragchakraborty7607
@anuragchakraborty7607 2 жыл бұрын
Best approach i must say
@ajmalaboobacker661
@ajmalaboobacker661 3 жыл бұрын
With this approach, wouldn't we have a collision in the "shortUrl" map if we passed in 2 url's with the same length?
@bernardpark3196
@bernardpark3196 3 жыл бұрын
Nope, as we’re using the URL value as the key and not the URL length e.g., encodeMap[youtube/abc] encodeMap[youtube/def]
@Abhishek-tv8px
@Abhishek-tv8px 2 жыл бұрын
hi which language did you use in the google coding interview, was it Python
@subhashreebanik8131
@subhashreebanik8131 7 ай бұрын
Yes. I asked him the same question earlier.
@RaghavAggarwal-f8w
@RaghavAggarwal-f8w 10 ай бұрын
we dont need encoded map. having just the decoded map is sufficient.
@vidhanrathore5954
@vidhanrathore5954 2 жыл бұрын
how your getting this power of 10 i don't understand this
@peterkim1867
@peterkim1867 2 жыл бұрын
Numbers as we use them in day-to-day life are base 10, so for a single spot you can have 10 possible options: 0,1,2,3,4,5,6,7,8,9 So if we have 10 spots, we can have up to 10 billion possible different numbers. Let's say that they wanted to store more inside those 10 digits, then we would need a higher base and a different way of reading the numbers. Hence, the numbers and letters.
@AashishM007
@AashishM007 11 ай бұрын
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
@rickyc46
@rickyc46 5 күн бұрын
😂😂😂
@Ankit-hs9nb
@Ankit-hs9nb 2 жыл бұрын
str(len(self.encodeMap) + 1) We need to add self
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 148 М.
Encode and Decode Strings - Leetcode 271 - Python
11:33
NeetCode
Рет қаралды 272 М.
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 96 МЛН
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 96 МЛН
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 8 МЛН
Design Twitter - Leetcode 355 - Python
22:47
NeetCode
Рет қаралды 91 М.
Why is everyone LYING?
7:56
NeetCodeIO
Рет қаралды 350 М.
How I Failed the Google Coding Interview (and lessons I learned)
14:24
Decode String - Leetcode 394 - Python
16:26
NeetCode
Рет қаралды 92 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 329 М.
System Design Interview Question: Design URL Shortener
13:25
Hayk Simonyan
Рет қаралды 12 М.
Dijkstra's Algorithm - Computerphile
10:43
Computerphile
Рет қаралды 1,3 МЛН
20 System Design Concepts Explained in 10 Minutes
11:41
NeetCode
Рет қаралды 1 МЛН
Tiny URL - System Design Interview Question (URL shortener)
9:39