Amazon Interview Question for Software Engineer / Developers


Country: United States




Comment hidden because of low score. Click to expand.
1
of 1 vote

create a table of
ID | URL
01| index.php
02| store.php
03| about.php
....

for short url use ID converted to Base36

to get full url we:
1. get short url from request,
2. convert it to lower case
3. decode to decimal
4. get full url

- klec@speroteck.com July 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about this approach?

Generate a random string of fixed length based on the character set that is URL-safe.
For ex: Suppose we want to generate a 6-char length string, generate 6 random characters from a URL-safe character set. Once you generate the random string, say h6Tu6M, use it to build a short-form URL like: shrt.ul/h6Tu6M.

Use a mapping table(say a hashtable) to map the short URL to the long URL.
Ex: h6Tu6M => domainwithlongname/with/lengthy/resource/path In this step we also need to ensure that the randomly generated string is not already in use. In case a duplicate is generated, try creating another random string.

The app which is hosted at: h t t p : shrt.ul/ can look up the short resource path h6Tu6M and redirect the user to the actual resource h t t p://w w w .domainwithlongname/with/lengthy/resource/path

- Murali Mohan July 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Get the hash of the actual url fold the url so that the size is reduced and check for same url in the db.store the url in a dictionary so that to map to original ....

<--please do down vote for wrong or in appropriate answer and explain -->

- sarath s pillai July 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

cskj

- Anonymous July 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

stackoverflow.com/a/1562793

- __xy__ July 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use a hash function to generate a hash value for a string url...
create a hashmap using this hash function for the original URL to store...

www . tinyurl . com / hashvalue
as tiny url for the web URL...

- coding.arya July 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) In java create servlet with short url pattern
2) In web.xml while mapping map short url to long url
3)Then short url will represent long url

- Vamshi krishna July 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A hash function could be implemented such that it takes current time-stamp and also the URL being shortened into consideration, so as to minimize the number of clashes. Of course you need to implement and check from hash table if the hash value exists.

- r20rock July 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There is another solution to this problem.
1) Create a database with Row/Column the rows and colums are numbered from aaa-ZZZ
2) Have a trie with leaf node storing the database RowColumn value, for example if the URL is stored in aBP row and Dqr column then the leaf will store the aBPDqr.
3) Now for the input url find if the input url is in the trie, if its found return the six character database value or else create an entry into the first empty location of database and store the RowColumn value in the trie structure and return the tiny URL with the six character database value that represents unique row and column.

The advantage is there is no guess work regarding how well your hashing function has generated a hash code and whether two different URL's can result in same hash code.

- Saket February 10, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

ddmwm

- qwdqw July 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

1. Get a tiny domain name like bit.ly, goo.gl, or is.gd

2. Create a URI to shorten the website with the actual URL, e.g., h t t p: / / w w w.myverylongwebsitename.com/blab/blah/blah/ becomes h t t p : / / goo.gl/mVLwsnWx. You can do this by using a good hash function that generates a unique and short string for the website.

3. Implement h t t p: / / goo.gl/mVLwsnWx as a HTTP redirect to the actual website.This can be implemented as a RESTful service, so when you do HTTP.GET h t t p : / / goo.gl/mVLwsnWx, the service redirects you to the actual website.

- oOZz July 26, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More