Amazon interview question

How can design a TinyURL for a website? Design an algorithm and write sample code which generates TinyURL for a website.

Interview Answers

Anonymous

7 Aug 2013

Take the URL and run it through a hash algorithm like md5 that can take arbitrary length input string and convert it to a fixed length hash value. Append the hash value to tinyurl like "http://tinyurl.com/".

2

Anonymous

7 Aug 2013

And you'll obviously need to make sure your webserver then expands the "http://tinyurl,com/" to the full URL by looking up some database.