I've been looking for a new job. Interviewed at a really cool company. My first interview was 6 hours of oral interviewing (lots of puzzles) followed by a programming test, which I didn't do too great on. I was called in for a second programming test.
I had to do this problem, and I took forever trying to come up with the solution (didn't help that my Standard Template Library was rusty), which I never actually did. I did come up with a wrong solution that was close, but I had to present it and got comments like, "What took you so long?" and "Quite frankly, I'm not impressed" and "This was your second chance" (implying the results of the second chance were not good). So yeah, I suck.
I will now share the final interview problem. Feel free to tell me how fucking easy this is:
Let's say you've got lots of data like this in a file:
Imagine hundreds of these, for lots of states, regions, sizes small medium and large, and all kinds of majors.
You had to write a function that given two schools would determine the set of attributes (they called these "predicates" in the problem) of those two schools that makes that pair unique. This conjnction of predicates should be the minimum necessary to make the pair of schools unique.
For example, in the case above (let's assume the NJ schools you see are the only NJ schools in the entire list), if you were given Princeton and Seton Hall, you could determine that those two schools are the only Private Schools in NJ. So the "State" and "Type" predicates differentiate that pair. You could also say that Princeton and Seton Hall are the only two private, Northeast schools in NJ, but the "Northeast" part is unecessary. Again you want the minimum # of predicates.
If the pair given is not distinct at all (there are other schools with the same values as the values in common between the pair), return NULL.
What I did (which was wrong and didn't satisfy the minimum size requirement) was have an array of 5 hash maps (5 for the 5 predicate categories), each map using the predicate value as the key (like State map has keys like "NJ", "MA", etc.), and a vector as the value. The vector holds the schools that are associated with that key (so the State hash map might have a [key,value] pair of [NJ, Princeton;Rutgers;Seton Hall]).
So my function, when given two schools, sees which values are in common (since for the conjunction to occur, the two schools need to have at least some data in common). Let's say their State (PA), Size (Large) and Region (Northeast) match up. I do an intersection amongst the State->PA vector, Size->Large vector and Region->Northeast vector. The final intersection should only contain 2 schools. If not, that conjunction isn't valid and you return NULL.
The problem of course, is that just taking the intersection doesn't give you the minimum set. With the Princeton/Seton Hall example, my algorithm DOES list "Region" as one of the predicates (Region should never be listed really, as it's a superset of state).
What you could do is try every combination of intersections for a brute force solution (say 4 predicates match; try intersections among all combinations of 3 of those predicates, then all combinations of 2, etc.), but brute force is not good enough.
I spent 20 hours interviewing at this company for nothing! The worst part is that I feel really fucking incompetent. But it also sucks that I missed out on a great salary there.
I will post questions from the first interview later if anyone cares.
I had to do this problem, and I took forever trying to come up with the solution (didn't help that my Standard Template Library was rusty), which I never actually did. I did come up with a wrong solution that was close, but I had to present it and got comments like, "What took you so long?" and "Quite frankly, I'm not impressed" and "This was your second chance" (implying the results of the second chance were not good). So yeah, I suck.
I will now share the final interview problem. Feel free to tell me how fucking easy this is:
Let's say you've got lots of data like this in a file:
Code:
School State Region Type Size Renowned Major
----------------------------------------------------------------------------------
Rutgers NJ Northeast Public Large Social
Princeton NJ Northeast Private Large PoliSci
Seton Hall NJ Northeast Private Small Whatever
Faketown TX Midwest Private Medium Whatever
Superfake MA Northeast Private Large Blah
You had to write a function that given two schools would determine the set of attributes (they called these "predicates" in the problem) of those two schools that makes that pair unique. This conjnction of predicates should be the minimum necessary to make the pair of schools unique.
For example, in the case above (let's assume the NJ schools you see are the only NJ schools in the entire list), if you were given Princeton and Seton Hall, you could determine that those two schools are the only Private Schools in NJ. So the "State" and "Type" predicates differentiate that pair. You could also say that Princeton and Seton Hall are the only two private, Northeast schools in NJ, but the "Northeast" part is unecessary. Again you want the minimum # of predicates.
If the pair given is not distinct at all (there are other schools with the same values as the values in common between the pair), return NULL.
What I did (which was wrong and didn't satisfy the minimum size requirement) was have an array of 5 hash maps (5 for the 5 predicate categories), each map using the predicate value as the key (like State map has keys like "NJ", "MA", etc.), and a vector as the value. The vector holds the schools that are associated with that key (so the State hash map might have a [key,value] pair of [NJ, Princeton;Rutgers;Seton Hall]).
So my function, when given two schools, sees which values are in common (since for the conjunction to occur, the two schools need to have at least some data in common). Let's say their State (PA), Size (Large) and Region (Northeast) match up. I do an intersection amongst the State->PA vector, Size->Large vector and Region->Northeast vector. The final intersection should only contain 2 schools. If not, that conjunction isn't valid and you return NULL.
The problem of course, is that just taking the intersection doesn't give you the minimum set. With the Princeton/Seton Hall example, my algorithm DOES list "Region" as one of the predicates (Region should never be listed really, as it's a superset of state).
What you could do is try every combination of intersections for a brute force solution (say 4 predicates match; try intersections among all combinations of 3 of those predicates, then all combinations of 2, etc.), but brute force is not good enough.
I spent 20 hours interviewing at this company for nothing! The worst part is that I feel really fucking incompetent. But it also sucks that I missed out on a great salary there.
I will post questions from the first interview later if anyone cares.