Facebook Interview Question for Software Engineer / Developers


Country: United States




Comment hidden because of low score. Click to expand.
3
of 5 vote

Everytime when a url is to be shortened, url_id field is incremented, url_id is converted to base-36 ( 26 alphabets + 10 digits ) OR base-62 ( 26 small alphabets + 26 capital alphabets + 10 digits ) which serves as primary key for each tuple. A string i.e. the actual url is added corresponding to this key in database. The primary key is appended to service providers domain name after '/' and returned to the user.

Usually its better to add a new url_id rather than searching for existence of a url in database. So same url can be shortened to multiple short url's.

But some sites do take care of not adding multiple short url's in database if same user try to reproduce it. They consider user location for this purpose.

- Cerberuz September 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If people think allowing same url to map to multiple IDs might lead to a (D)DOS attack, consuming the id space, think again.

- Anonymous September 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

DDOS attack is a different thing, i think the service provider takes care of such things when considering multiple ids for same url ( complete consumption of id space is a rare case, DDOS attack will have to be of huge order and extremely fast to do that ). Moreover i already specified that some sites don't add multiple id's for same url e.g tinyurl while some sites do e.g google url shortener.

- Cerberuz September 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Cerebruz: That comment seems to be in support of your answer, isn't it?

- Anonymous September 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Little more info from google URL shortener :

The Google URL Shortener provides different functionality based on whether or not you are signed in:
: If you are signed in to goo.gl using a Google Account, a unique short URL is generated each time a long URL is shortened.
: If you are not signed in to goo.gl, the same short URL is reused each time a long URL is shortened, across multiple users

- Cerberuz September 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 3 vote

use hashmap,

break url in 2 portion, one is the domain name part and other is rest one,

now apply hashfunction on both separately and concatenate them,(this will reduce chance of collision).

if the given url is already used then return the previously used hash value.

- niraj.nijju September 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 4 vote

I guess we can apply hashmap funda here............take the sitename as input to hasfunction ...the output of the hashfunction is your tinyURL and map it to the IP address in the hashtable..... :-/

- Mukesh Kumar Verma September 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What if two tiny URL point to same link.. How will you handle that case..

- loveCoding September 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

why not return the already present hash value?

- chandershivdasani September 13, 2012 | Flag


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