Ebay Interview Question for Software Engineer / Developers


Team: Traffic
Country: United States
Interview Type: In-Person




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

TinyUrl is to shorten the long urls which is more handy.
we can do that using hash table/database to do this.
1. Hash the long url which user gives, and store this new along with user given url.
2. when user give shortened url generated in step 1, system will retrieve original url matching the shortened url in hashtable.

- Vivek January 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Need to design for a large sysmet which will hold millions of URL's

- juny January 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Database to be used to solve scalability problem.

- Vivek January 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Stronger hash function will do a better job if it is to hold millions of URL's but it will not be a tinyurl anymore

- pras April 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

General working of TinyUrl is:
If same long url is given multiple times (or multiple users), different tiny urls need to be given.


So, we can start with a 3 character combination and increase the number of character combinations when they are exhausted. Add the character combination as a key and the long url as value in the hashtable. So when the tinyurl is given, the value against this in the hash table is fetched in constant time.

Please do comment your opinions.

- praveen September 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Redirect Part:

When you click on a link of any tiny url, an HTTP Request is sent to their server with the full URL, like http // bit.ly / b9 (not a real one).

They read the path part (here b9), which maps to their Database.

In the Database, they find the real URL. Then they issue a redirect, which is a HTTP 302 response and the target URL in the header.

Encoding Part:

One of the most popular URL shortening services simply take the ID in the database of the URL and then convert it to Base 62[a-zA-Z0-9].

import static org.testing.AssertJUnit.assertEquals ;

public class TinyURL {
	private static final String ALPHABET_MAP = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ;
	private static final int BASE = ALPHABET_MAP.length() ;

	public static String encode ( int IndexNum ) {
		StringBuilder sb = new StringBuilder() ;
		
		while ( IndexNum > 0 ) {
			sb.append ( ALPHABET_MAP.charAt ( IndexNum % BASE ) ) ;
			IndexNum /= BASE ;
		}
		return sb.reverse().toString() ;
	}

	public static int decode ( String str ) {
		int Num = 0 ;

		for ( int i = 0, len = str.length(); i < len; i++ ) {
			Num = Num * BASE + ALPHABET_MAP.indexOf ( str.charAt(i) ) ;
		}
		return Num ;
	}

	public static void main ( String[] args ) {
		//System.out.println ( "Encoding for 123 is " + encode(123) ) ;
		//System.out.println ( "Decoding for b9 is " + decode ("b9" ) ) ;

		assertEquals ( "b9", encode(123) ) ;
		assertEquals ( 123, decode("b9") ) ; 
	}
}

- R@M3$H.N January 01, 2015 | 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