• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interview Questions

 
Randi Cott
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just had an interview, here is a couple of the questions I was asked:
1. What do you look for in a specification in order to create a good program design.
2. Given an unsigned 16 bit integer and unlimited memory, provide an alogorithm which will determine the bits that are set.
3. What causes memory leaks in Java.
 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Randi",
Welcome to JavaRanch.
PROPER NAMES ARE NOW REQUIRED
Please look carefully at official naming policy at javaranch & reregister yourself with proper first & last name, with a space between them. Please adhere to official naming policy & help maintain the decorum of the forum. The naming policy can be found at http://www.javaranch.com/name.jsp
Topics posted by people with invalid names will be closed. Please register with a new name and this topic will be reopened.

--Mark
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randi, were you just commenting on what you were asked, or did you have a question about these items?
 
Michael Morett
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I liked questions 1 and 3. But number 2?
(pauses to regain composure)
Barring grammatical errors in the formation of the question, I can't even understand what is being asked. Or the relevance. Is his/her expectation that you memorize algorithms? That you could write them on the spot, presumably on a blank sheet of paper with a pen? No logic errors? No compile-time errors?
A better approach would be to give you the problem to take home to solve (assuming the problem is representative of a realistic scenario to be encountered on the job). At least you could resolve it in a real world environment: you have access to your plethora of algorithm books, an IDE, and time to work out the problem.
Maybe it's just me, but the expectation placed on this guy is immature. None of us work like that. I understand the need to verify skills claimed, but this seems petty.
Those that can pull off that exercise in trivia need to be applauded.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I think the interviewer is trying to measure problem-solving ability. I think it's actually a nice little test. If you are competent in core java, you should have an understanding of bit shifting and masking, so assuming this ability for the moment, I think the question is narrow enough to be tackled in a short period of time.
If I were the interviewer I wouldn't be expecting a flawless algorithm. I would be more interested in seeing how the candidate dealt with solving the problem, the steps he took, how he reacted under pressure, etc. These insights would be far more valuable to me than a complete, correct solution to the problem.
 
Randi Cott
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was just wondering how others felt about this line of questioning.
Regarding #2 (and note that this came after an hour of grilling me) I totally blanked out and could not come up with an answer on the spot...of course now I can think of numerous ways to do it....anyway his answer was...
convert the # to binary
create a character array to store the bit pattern.
parse through the array and print out the indexes of the '1's. That was it!
I also did not understand the question, as he worded it, nor did I understand #1.
Can anyone tell me the answer to #3?
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the discussion in this thread:
http://www.coderanch.com/t/369424/java/java/memory-leak-Java
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I'm sure someone else could have been sleeker, but those two came to mind quickly.
The while loop in usingString(int) only executes for every '1' bit, but I don't know what the cost of the lastIndexOf() call is.
On the other hand, in usingShifts(int) the while loop executes from the least significant to the most significant bit, but the shift operation is far less costly then the lastIndexOf().
[ June 12, 2002: Message edited by: Jason Menard ]
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question said memory was unlimited. If you really, really wanted something fast.
1. create an array of 64K Strings, where each String is a representation of the bits corresponding to the array index.
2. use the 16-bit int in question to lookup the String, and print it out.
Assuming you only do #1 once, but are using #2 a lot, and you don't care about memory (including not caring about any underlying page swaps), then this would be very fast.
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jason Menard:
I'm sure someone else could have been sleeker, but those two came to mind quickly.

Authors of toBinaryString method, had They use "... AND mask" to test lowest bit. If we look at how toBinaryString() method is implemented, there is only one line:
<pre>
public static String toBinaryString(int i) {
return toUnsignedString(i, 1);
</pre>
and toUnsignedString() looks like
<pre>
private static String toUnsignedString(int i, int shift) {
char[] buf = new char[32];
int charPos = 32;
int radix = 1 << shift; // 2<br /> int mask = radix - 1; // 1<br /> do {<br /> buf[--charPos] = digits[i & mask];<br /> i >>>= shift;
} while (i != 0);
return new String(buf, charPos, (32 - charPos));
}
</pre>
and "digits" array declared as
<pre>
final static char[] digits = {
'0' , '1' , '2' , '3' , '4' , '5' ,
'6' , '7' , '8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
'o' , 'p' , 'q' , 'r' , 's' , 't' ,
'u' , 'v' , 'w' , 'x' , 'y' , 'z'
};
</pre>
"mask" in our case is 1, so "i & mask" expression will yield 0 if i's lowest bit is zero and 1 otherwise.
[ June 12, 2002: Message edited by: Mapraputa Is ]
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Randi Cott:
anyway his answer was...
convert the # to binary
create a character array to store the bit pattern.
parse through the array and print out the indexes of the '1's. That was it!

What "convert the # to binary" means? Aforementioned toBinaryString() method?
Originally posted by Jason Menard:
On the other hand, in usingShifts(int) the while loop executes from the least significant to the most significant bit, but the shift operation is far less costly then the lastIndexOf().

Not sure what "most significant bit" means, but your loop will be executed until there are only 0s left, so for input number 5, for example, there will be three iterations.
[ June 12, 2002: Message edited by: Mapraputa Is ]
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what "most significant bit" means, but your loop will be executed until there are only 0s left, so for input number 5, for example, there will be three iterations.
Yeah, that's what I said! Most significant bit is basically the highest-ordered 1 bit.
As for what the 'real' Java guys did regarding the logical ANDing... that is more efficient than the MOD operation in my second example. They obviously (and rightly so) put more thought into the problem than I or the interviewer did, luckily for all of us.
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jason Menard:

Yeah, that's what I said! Most significant bit is basically the highest-ordered 1 bit.

Ah, I thought maybe you mean highest-ordered 1 bit, but then decided it would be unfair to "least significant bit" which apparently is "least significant" regardless of its value.
(Sometimes I feel an urge to jim around )
 
Joseph Hammerman
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to question 3 is that you cannot have memory leaks like in C/C++. However, if you code so that the garbage collector thinks that memory is still being used, you can tie up a lot of memory.
There are a lot of answers to question 2, as the previous posts show. It should be pretty easy to come up with some kind of answer to it at an interview.
If you weren't able to answer questions 2 and 3, you probably didn't get the job.
None of these three questions are particularly difficult. I think they are good questions. The answers should give an idea of the persons level and how he/she approaches a problem.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are interesetd in info about Java memory leaks and avoiding them, Chapter 6 of Manning's Bitter Java, dealing with just this issue, is available for free at their site.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bump.
 
Chris Leeworthy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a lighter note I'm sure they would have been nitpicked on the cattle drive for using that do{...}while loop!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic