Sunday, July 3, 2011

software engineer interview questions

1. I got asked this question at Gooogle. Given a tree data structure that can only traversed in one direction, i.e. from root to leaf, write a function that will take two nodes and find the lowest common ancestor. Somehow it took the guy asking the question about 10 minutes to say the question; but, there's nothing more to it.

This question assumes you have access to the tree root.

Start at the root and traverse through the entire tree until you find both nodes.
Along the way keep track of the path at all times. ( You can use a stack to push/pop nodes as you traverse up and down the tree.) When you find a node, inspect the stack to see the path.
Once you have both paths, you can start at the root of each path and move down until they branch off in different directions.

2. In Java, what's the difference between an abstract class and an interface? I get this question a lot in pre-interview phone screens.

If you can't answer this you don't deserve a job.

3. What's new in Java 5?

Generic's.

4. What is the jquery selector for this html element?
<type="button" value="Input Button"/>


"input [type=button]" ?

5. In Java, what's the difference between HashMap and HashTable?

One is thread safe.

6. What is polymorphism? I actually don't think people really understand what is the exact definition of this term. Anyway, if you get asked this question, they're testing if you know the rules for how/when methods in derived classes override methods in the parent classes.

Every class has a class hierarchy. If a class does not explicitly declare a parent class, it automatically derives from the class java.lang.Object.

Classes may declare methods with the same name as methods defined in classes above them in their class hierarchy. If they have different parameters, they will not override their parent counter parts. If they have different return types, they will generate a compile error. If at some point in the class hierarchy a method is declared final, it can not be declared in any class below it in the class hierarchy.

Given a method is declared with the same signature in two places in the class hierarchy, the method from the lowest class in the class hierarchy will be invoked, unless the method is invoked through reflection or other technique.

The end result is that given a piece of code that knows that an object is of a certain type, and given that the actual type of the object is one of any number of subtypes, when a method is invoked that is defined in each of the subtypes, the method that gets invoked will be the method defined in each subtype.

Did you catch all that?

No comments:

Post a Comment