Yahoo Interview Question for Software Engineer in Tests






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

if distance is the only thing we always want and we go with precomputed way.

lets say planets are abc and xyz(even god wont name the planets same :))
find a string abcxyz(i.e. concatenate both planet names) and store it as a key in hash table and distance as value.

Since its gonna be a huge hash table, we can have distributed hash table across n machines and deal with network latency.

Note: While concatenation always using Lexicographical smaller string first and larger string next, so that we don`t double the size of already huge hash table

- anonymous October 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can make a graph while edges represent the distance between two planets.

Comment??

- Anonymous October 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Monsterous data structure, very bad choice.

- Anonymous October 03, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I would create a tree like structure by partitioning the galaxy into blocks, then those blocks into blocks, etc. while finally storing the planet at the lowest level. For instance, block knows the VECTOR to all of the other blocks in it's level. Then to find the distance from Planet A to Planet B, you first get the vector from Planet A to Planet A's parent, then sum the vectors from Planet A's parent up until the top level, then to Planet B's toplevel, down to planet B. Eventually you will be left with a vector from A to B, and the magnitude is the distance.

- Anonymous October 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Basically an Octree you mean

- JD October 17, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

you'd be representing the entire galaxy in 3-d in the octree, in which case, the tree itself will be massive. the main problem would be that you are representing every inch of space in the blocks, which can really bloat the tree.

we could avoid this by using a multi-level hash tables, with the the first level having (planet A) and a second level which gives distances to all other planets. once we have coords of two planets, we use simple math to compute the distance. This would be O(n-1) for a given planet.

- hgk October 25, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

you'd be representing the entire galaxy in 3-d in the octree, in which case, the tree itself will be massive. the main problem would be that you are representing every inch of space in the blocks, which can really bloat the tree.

we could avoid this by using a multi-level hash tables, with the the first level having (planet A) and a second level which gives distances to all other planets. once we have coords of two planets, we use simple math to compute the distance. This would be O(n-1) for a given planet.

- hgk October 25, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

http://en.wikipedia.org/wiki/Closest_pair_of_points_problem

- Anonymous October 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

how about a 2-D array... But in this there will be 2x use of memory. Since it will be a symmetric array. So we can do a single 1-D array.. Lets assume that the planets are numbered.. So the index of planet number n will be n(n-1)/2 in the array.. and the next n elements will be distance of nth planet from all other planets.. This way we can reduce the memory usage to 1x.

- anon October 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1] project all the location from a 3-d to a 2-d plane.
2] Now consider one of the planet as the origin. Lets say earth :)
3] Store X and Y co-ordinate of each planet wrt to Origin. An array of structure.
struct Planet
{ char* name;
double x, y;
}
4] Use distance formula to calculate distance between any planets.

Opinions ?

- p1 October 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

struct planet {
planet_name;
double x, double y
}

vector: to store Planet type pointers
Hash Table: Key->value ==== planet_name -> index in vector
Algo:
1) Get planet_names;
2) lookup in hash and find index i and j resp for both planets
3) calculate distance simply using a simple mathematical formula.

- anonymous October 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

you should use r* trees for spatial structures

- anonymous July 26, 2010 | 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