Monday, April 6, 2009

More interview questions

Some good questions I got asked today with answers as well:

  1. When is machine code generated for java classes? (google Just In Time [JIT] compiler)
  2. If I compile java code on one OS, can I move the class files to another machine and run them there? (yes)
  3. Are primitives passed by reference or value to methods? (value)
  4. What does Microsoft's OLE stand for? What is ActiveX? (Object Linking and Embedding, and google ActiveX)
  5. Is Java a managed or unmanaged language? Are memory leaks possible? If so, how would you make one? (managed, yes, and too complicated to explain briefly)
My programming question was to reverse an array of integers. I also had to give time complexity in O(n) notation for both my solution and an alternate one.

I also received a logic question at the end which I found interesting. I'll repeat it here:

There are three jars which you cannot see into. One of them contains black marbles, one contains white marbles, and one is mixed black and white (proportion unknown). There are already labels on the jars with "Black", "White" and "Mixed". However, every label is incorrect.

How many marbles do you need to draw out of which jars in order to figure out what should be the correct labeling?

Spoiler (Copy and paste):
The correct answer is 1, and it's out of the mixed jar. The key to the problem is that every jar is labeled incorrectly. If the marble that comes from the "mixed" jar is white, then that jar is actually ALL white. It can't be mixed because all the labels are definitely wrong. Via process of elimination you can figure out the other ones without drawing more ("black" must be mixed and "white" must be black).

2 comments:

  1. Oooh, I liked that logic question. Gotta try that one on my friends/family.

    ReplyDelete
  2. Hi

    I read this post two times.

    I like it so much, please try to keep posting.

    Let me introduce other material that may be good for our community.

    Source: Citigroup interview questions

    Best regards
    Henry

    ReplyDelete