i'm a fan of your channel. a small typo i see on line 11: len(encodeMap) -> len(self.encodeMap)
@NeetCode3 жыл бұрын
Thanks, good catch!
@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.
@bigboyshassen592 ай бұрын
sir, you can run into collisions with md5.
@yaronnir2 жыл бұрын
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......
@cw594811 ай бұрын
He did say characters and digits 4:30
@jkrigelman2 жыл бұрын
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 Жыл бұрын
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
@RemotHuman11 ай бұрын
Or just have the decode map and make a new entry every time you encode. How is this medium?
@forentrepreneurs38522 жыл бұрын
How about we save only the part after base in the hashTable to reduce space complexity?
@keshav15303 жыл бұрын
Why did you add 1 to the length of longUrl? URLs can't end with 0 or are there other reasons?
@crisag.2698 Жыл бұрын
He added 1 to the length of the encode map, not to the length of the string
@tonyz22032 жыл бұрын
Why did you add 1 to the length of longUrl?
@tarunshanmugam89057 ай бұрын
to start with 1 not zero
@anuragchakraborty76072 жыл бұрын
Best approach i must say
@ajmalaboobacker6613 жыл бұрын
With this approach, wouldn't we have a collision in the "shortUrl" map if we passed in 2 url's with the same length?
@bernardpark31963 жыл бұрын
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-tv8px2 жыл бұрын
hi which language did you use in the google coding interview, was it Python
@subhashreebanik81317 ай бұрын
Yes. I asked him the same question earlier.
@RaghavAggarwal-f8w10 ай бұрын
we dont need encoded map. having just the decoded map is sufficient.
@vidhanrathore59542 жыл бұрын
how your getting this power of 10 i don't understand this
@peterkim18672 жыл бұрын
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.
@AashishM00711 ай бұрын
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