I was asked to design a URL shortener in a fintech startup's interview.
For the basic part, I proposed using a MD5 kind of algorithm to generate a hash of the url, encode it and then take first 7 bytes of the string.
Next the interviewer asked me the following questions:
However, the interviewer mentioned that any hashing function would always produce collisions, so we can not use any hashing function while designing a URL shortener.
Somehow I could not agree with the statement. I proposed that we can append a pre-defined sequence number to the URL string and then regenerate the hash and check if it collides or not. In case it collides, then increase the sequence number and go on.
Question: