The Downfall of the Programming Interview
I’ve done a lot of interviewing at various companies in my life as a “software developer” or “systems programmer” and most of the time the questions asked aren’t the ones you might expect. If I was applying for a job doing GUI work I would expect questions that relate to building GUI’s. Do you sufficiently understand MFC or the Windows API? Can you write a simple GUI application that has a series of buttons, a menu and a text area?
However, more times then not the type of questions asked in the “technical” interview has been far from the questions you would expect. These are the questions one ask to show up another programmer instead of actually gauging his level of programming experience.
This is often frustrating for myself and others I know as a programmer because getting a job hangs not necessarily on your experience, but on whether you can answer these obscure questions.
Now don’t get me wrong I think that every new thing a programmer learns is like a new tool they have at there disposal. However, sometimes I would like an interviewer to actually ask me something that may come up on a daily basis instead of a hypothetical programming question.
What is an example of a hypothetical programming question? Ah, I’m glad you asked.
The Question
“Assume that in your given language you have found yourself without the multiplication sign. How would you divide 2 integers together.”
Now you sit there and look at the paper asking yourself, why in the world would you not have a multiplication sign. Now I’ve read a lot of programming books and I’ve never seen someone put a chapter called, “How to make a function call when the language doesn’t support it, but you damn well need it”.
Now I know the solution isn’t terrible, however, the general solution isn’t the point…
The Crap Solution
int MultiplyIntegers(int A, int B)
{
int C = 0;
while (B != 0)
{
C+=A;
B = B - 1;
}
return C;
}
The point is that this is just the beginning… What if they asked you “How do you divide 2 floating point numbers without the division sign?” or “Increment a value by 1 without using ”+” or ”-” in your code?”
The goal of this an future articles is to expose as many of these possible interview questions until everyone knows them and they start asking *actual relevant” questions… So here is for your enjoyment my other solution to this specific problem
A Better Solution
int MultiplyIntegers(int A, int B)
{
int C = 0;
while (B != 0)
{
if ((B & 1) != 0)
C += A;
A <<= 1;
B >>= 1;
}
return C;
}
cout << MultiplyIntegers(4, 5) << endl;
The output is “20”.
How it works
This isn’t a real crash course in binary, however, I may if time is available explain more beginner topics at length. Right now this is just things to get you to pass the interview and get that job you really want.
B = 0000 0101
A = 0000 0100
0000 0101 & 0000 0001 != 0
C += A
C = 4
———
B = 0000 0010
A = 0000 1000
0000 0010 & 0000 0001 == 0
C = 4
———
B = 0000 0001
A = 0001 0000
0000 0001 & 0000 0001 != 0
C += A
C = 16 + 4
C = 20
Final thoughts
This isn’t to say this is the only solution to answer this. However, if you give this solution instead of say the rushed one you might have come up with before you may just get that job you’ve always wanted.
I hope to bring you other cool tricks to impress your friends – defeat you enemies and possibly show that interviewer that you nobody’s fool.
Click here for a other articles in the blog section.
Walter Reid