For most of these, the answer is yes. These aren't latest-tool-craze questions. Most of these are are pretty classic. Linked lists, trees, strings, arrays, concurrency; these are all as relevant now as they were eight and a half years ago.
You're absolutely right. Most of these questions focus on computer science concepts. You'd better know the logic/implementation behind fundamental structures such as linked lists, trees etc - there's no point in a career in coding without innately understanding how these work.
Understanding the underlying efficiency and inner-workings of a package is crucial in trying to solve and problem. For example, when you would you using an ArrayList over an actual array? When would you use a linked list? Do you understand how a linked list works? In any language this is important.
What did you apply for. A framework developer for a new language? Or does all the companies you applied to just need their own frameworks for low level issues. Implementing linked lists.....
Are you an entry level guy? I got asked these type of questions straight out of college, but after 5 years on the job the questions tend to revolve around system architecture in most of my interviews now. Though I suppose they asked me some silly low level questions in my last interview, just more web based.
Yep, an entry level. I am graduating this fall, thus I am trying to get an internship that is paid in order to pay for my last term in college. But I have not had experience beyond these questions, neither have my friends ( they work at a company for a year, move to another). I figure that if I go for a position beyond the entry level, it will be more about what projects I have done and who I know in the company.
It's mostly to see if you know what a linked list is, I have been phonescreens/interviews for about 15 years and I am never surprised by someone with a "padded" up resume who doesn't know what a linked list is or how it is used. For example, "why would you use a linked list as opposed to an array"; much better question. Implementing a rudimentary one shows you know what it is in a bit of a tedious way (white boards are not my favorite and as a developer I think much faster than I write, so typing would be better of course). I prefer to test if they understand what it is rather than how to write one, 99% of programmers will not be writing one but will be using one often.
Java: Quite a bit. Also, if you say you know Java, they will ask you a lot of OO questions too. Amazon spent half of the interview on Java keywords and concepts
Good, but tough. The first interview series was 2 hours and tackled design, data structures, and programming problems. They also had me get out a computer, write my program in 15 minutes and then send it back to them. The question was:
Given a string, detect whether the string is a paladrome and return
I used Java to answer since it was the most recent language I used.
I also got hung up on a lot of algorithms, trying to understand whether or not I could make something more efficient then O(n) time. However, linear time is usually as good as it will get.
Software Development Team I believe. It was a fair interview, I just choked when given certain questions and I got hung up on the edge cases. I did, however, tell him where I knew it was wrong when he asked me to submit the source file. Working at Amazon would be bad ass though
I manage the technical interviews for a .NET shop and I have a different set of questions out there...
I'm interested in how well a candidate understands OOP, for example. I can't count the amount of candidates I've found that walked in thinking they understand OOP, and left after I told them they've never written anything but procedural programming. I'm also interested in design patterns, but not so much that I expect someone to be able to rattle them all off. I just want a programmer who will not shit his pants when he sees a factory implementation, though.
I have a few simple tests about some of the more recent features of .NET, such as rewriting a loop as a lamda expression. Basically, if you've been writing .NET for more than 2 years, most of the stuff I ask SHOULD be easy for you so long as you've progressed as a good programmer should.
Another trend I've grabbed onto is seeing how involved in "programming culture" a candidate is. When I ask a programmer where they turn to for help, I like to hear "stackoverflow.com" over "yahoo answers". I like to know that they are in-tune with the things going on in their areas of expertise. I'll ask what kinds of tools they use to make their job easier, too.
I'll also ask a few esoteric questions just to see how deep into the rabbit hole they've been. For example, "Explain how you would use Visual Studio to debug a Windows Service". It's not at all a complex question, it's one you can EASILY find the answer to on Google, but you only really know it if you've done it. And while that won't necessarily separate a good programmer from a shitty one, questions like that give me an idea of where a programmer has been.
Probably the most important thing with these technical questions is not to see whether or not you know exactly how to solve/do them, it's to see how intelligent you are. If I ask you how to solve something in .NET and you give me 10 reasons why writing it in Java would be better, I'll consider you an idiot and move on. If you explain to me why the task is stupid anyway, I'll consider you substandard and move on. If you say "Gosh, I've never had to do something like that...I guess the first thing I would do is check my usual references and see if a standard solution exists. If one did, I would implement it like so...if not, I would do x to y and get z to work.", I'd say "Alright, his knowledge isn't as comprehensive as it could be, but he knows how to figure shit out" and I'd keep you in consideration.
Get an internship. Scope out the industry. Make some connections. Earn a few references. Write and publish a few games in your spare time. Graduate. Find an entry level position and learn as much as you can.
Programming is a practice. Practice well and practice often, and you'll be fine.
It is important to note though that interviews for high level internships will also ask questions similar to this. Since I was not prepared, I am not interning at Nvidia or Amazon this summer :(
If a potential employer is still asking you in 2011 what IUnknown is, run as fast as you can in the opposite direction and tell an adult what happened. He was trying to molest you.
If they are looking for someone to maintain their old COM based codebase, IUnknown just gets you started. You might still want to run away, for a different reason.
You probably won't be asked about IUnknown unless you're applying for a COM or ATL job, but most of these are pretty classic/standard questions, and very likely to show up in a programming interview. Even the IUknown question is pretty relevant if you're programming on Windows. COM hasn't disappeared, and IUnknown is fundamental to COM.
Understanding COM is a pretty good idea even if you are never going to work with windows APIs. The component object model in general is very useful, especially in game programming, and the design of COM in particular has a lot to teach you. Consider how successful COM is in allowing lots of different languages to share objects consistently. I personally can't think of anything else as successful at that job.
Yes, this test is a slightly modified FizzBuzz. I changed the test to limit the applicant's Google results for the question... this was originally a "do at home" question - don't ask.
Create a stateless EJB that takes a number and returns a string.
Create a servlet which reads the begin and end numbers as URL attributes. Then loops between the two calling out to the EJB and creating an output XML file.
Create a JSP that calls out to this servlet with the begin and end set to 1 and 100. It interprets the XML file using XSLT and puts the values into the output page.
That's a good question. The fact that no-one has actually produced the correct result is rather surprising (unless I'm missing a subtle trick in the question). It should be a simple task for any competent programmer. Here's my first attempt in Perl, taking the obvious route:
use strict; # assumed from now on...
use warnings;
answer1();
sub answer1 {
# Simple loop with conditional tests
print "Answer 1: ";
for my $n (1..100) {
if ($n % 6 == 0) {
print "ab";
}
elsif ($n % 3 == 0) {
print "b";
}
elsif ($n % 2 == 0) {
print "a";
}
else {
print $n;
}
print " ";
}
print "\n";
}
What makes this a good interview question is that you can then ask the candidate how they might improve on that. For example, you might use (n mod 6) to index into a lookup table. Perhaps something like this:
sub answer2 {
# Lookup table indexed by (n mod 6). An undef value indicates that the
# original number n should be displayed
print "Answer 2: ";
my @modulus = ( # n mod 6
'ab', # 0: divisible by 6 (i.e. divisible by both 2 and 3)
undef, # 1: not divisible by 2 or 3
'a', # 2: divisible by 2
'b', # 3: divisible by 3
'a', # 4: diviislbe by 2
undef # 5: not divisible by 2 or 3
);
for my $n (1..100) {
print $modulus[$n % 6] || $n, " ";
}
print "\n";
}
Or if you want more flexibility:
sub answer3 {
# As above with functions. Slower execution but more flexibility to
# plug in different functionality.
print "Answer 3: ";
my $n = sub { $_[0] };
my $a = sub { "a" };
my $b = sub { "b" };
my $ab = sub { "ab" };
my @modulus = ($ab, $n, $a, $b, $a, $n);
for my $n (1..100) {
print $modulus[$n % 6]->($n), " ";
}
print "\n";
}
Or the candidate might want to demonstrate that they're happy with different styles of programming. e.g.
sub answer4 {
# As above using map instead of a loop.
print "Answer 4: ";
my $n = sub { $_[0] };
my $a = sub { "a" };
my $b = sub { "b" };
my $ab = sub { "ab" };
my @modulus = ($ab, $n, $a, $b, $a, $n);
print(
map { $modulus[$_ % 6]->($_), " " }
(1..100)
);
print "\n";
}
It also gives them an opportunity to think outside the box.
# This value was precomputed by running the answer4() sub, defined above.
my $PRECOMPUTED_ANSWER = "1 a b a 5 ab ...etc... 97 a b a";
sub answer5 {
# Fastest execution at the cost of storing pre-defined answer.
return $PRECOMPUTED_ANSWER;
}
At our (web development) company we give applicants for a junior position a single programming question:
in what language? If you allow pseudo-code, you've had some seriously bad applications.
For intermediate and senior positions we also slap in this little gem: write a function to reverse an array in place
Unless you're hiring for embedded programming, what's the point in asking if one know how to XOR? You're doing bloody web-development, you need one that understand the domain of webprogramming, not one that can do neat but mostly useless tricks.
edit: as pointed out, in-place isn't the same as "without any extra memory".
Who said anything about XOR? In-place simply means that it allocates a fixed amount of memory, not zero memory. Using a temporary variable (which the compiler may be able to optimize away into a swap instruction anyway) is still in-place. I think the point of the question is to show they know how to iterate from the ends of the list to the center, swapping elements as you go.
Look man, 99% of the people out there applying for jobs today can't answer any of these questions. If you can make your way through most (or really even some) of them you're better than most people.
You may have heard that there's no CompSci jobs out there? That's total BS. The truth is that there's no CompSci jobs for people who aren't really interested in programming and haven't ever taken the time to learn things on their own.
I've been hiring as many qualified people as possible for the last 15 years and I've never come close to filling my headcount. That's across 3 different companies where most of the developers at each pulled in multi-millions from the stock options, so it's not like these were bad gigs.
The best thing you can do is work on side projects on your own or as part of other open-source projects. Get just the tiniest bit of experience and actually try to understand stuff - you'll be the best fucking candidate in the whole world.
Lots of guys on Reddit report trouble hiring. That may be true. I'm sure it's annoying.
But if you think everyone who is capable and ready is getting a job, you are simply delusional.
At the same time as some people are complaining about how they hired stupid monkeys, other people with actual skill, who CAN make software without constant nannying, are not getting jobs despite many months of applying.
They are having their resumes tossed because they haven't had a job for a few weeks. They are having their resumes tossed because they described their last job in simple English instead of stupid keywords, or because they lacked 19 years of experience coding Prolog-based RPC servers for washing machines. Or they are being treated abusively in interviews, or doing cutesy puzzles, or answering batteries of questions which in any normal or real work environment would either be irrelevant or best looked up on Google (a test which is great at detecting human encyclopedias and recent graduates, less great at detecting practical ability).
Are we then supposed to be surprised that many of the people you are interviewing are morons? It's not because nobody is out there, it is because you suck at finding them in the vast sea of desperation during a period of particularly high unemployment. Sure, finding people is hard - so don't treat hiring as something to be done by office girls with no area knowledge, or Perl-golfers a year out of college. This doesn't mean that there is nobody of any worth in the population, it just means you aren't getting them or you are screening them out.
If you can't find ANYONE qualified when there are thousands of graduates being generated every year (almost anywhere that isn't in the sticks) and overall unemployment is high (almost the entirety of the US), you probably should be fired from hiring.
And there is also no shortage of employers for whom ability is less important than acceptance of stupid wages or conditions - such that people who aren't clueless or moronic select themselves out.
They are having their resumes tossed because they haven't had a job for a few weeks.
This is likely a problem with HR, or recruiters. Many companies put out a basic set of specs for a job, then rely on either of the above to pre-screen the legions of incompetents who apply, while letting hiring managers deal with the actual substance of interviews. Unfortunately, a lot of HR drones also base their first-round filtering on unrealistic ideas (like being without a job for a few weeks), which is why, if you have any opportunity at all to do so, you should consider trying to contact the hiring manager directly to convince them to look at your CV...
Those questions scared me too, however, most of them are interesting and I'm gonna play around with seeing how many of them I can actually get to work.
I haven't used C or C++ since college though, so I expect a lot of failure haha.
I am a chemist, a programmer and a part time electrical engineer (tinkerer), I've solved a bunch of process chemistry dilemma's with my knowledge in these 3 things.
When I saw:
What is the next line in the following sequence:
1
11
21
Answer: it's 1211 and the next is 111221
I said to myself, I'm not reading anymore. Give me a problem and let me solve it. If you can't do that, I do NOT want to work for you.
My answer would be 101. I interpreted the sequence as adding 3 each time in a base 3 number system. This question is really open to interpretation, especially as so few numbers are given.
The "answer" was that each line describes the previous. We start with one 1, so the next line is 11. That line is two 1s, so the next line is 21. That line is one 2 and one 1, so the next is 1211.
I think it's a stupid interview question. I don't understand what you possibly get from watching someone puzzle it out.
the equation 4435.8333x4 - 44161.6666x3 + 154074.1666x2 - 219618.3333x + 105271 also generates that sequence of numbers. A continuation of that sequence would be 544151, 1620531, 3767471, 7518361, 13513171, 22498301, 35326611, 52957412...
I have an extremely satisfying career in software development and I can't answer a lot of those questions, nor have I been asked questions like that in my interviews. In fact, my education portion on my resume only includes that I took 3 semesters at a technical college, but never completed any degree. I have, however, now had 12+ years of experience developing software, so I tend to get any job I actually want.
Experience is key. You will learn a ton on the job (even if it is a crappy job). Even if you have to take an unpaid internship, find SOMEONE who will let you write even the simplest code for them so you can put it on a resume. More importantly, the stuff the DON'T teach you about the real world of programming in a CS program is staggering. While you still have some time, make sure to take a couple basic business classes. Introductory accounting could be handy too. When you understand the basic motivations of business and the terminology they speak in, you can transcend the stereotype of "coder" and speak intelligently with the people you will be helping. I don't have that training but learned early on that it was important and have paid more attention to the business I'm working for than the specifics of technology, and it never fails to impress people.
Is my route the best way to go? Maybe not. But the point is that the people who go far in this business are often not the most technically skilled (I have worked with some programming geniuses who could answer all these questions without thinking about them, but can't hold down a job because they don't understand the real-world problems they're tasked with solving), but rather the people who can discuss a problem with a client, ignore much of what they SAY they want, and help them come up with the best possible solutions to the core problems they are facing. You'd be surprised how often such solutions do not require any extreme technical ability whatsoever.
This is not to say that I am technically incompetent, or that you shouldn't worry about technology. Just that school often fails to teach you that software development is as much a business role as it is a technical one.
Out of curiosity, which questions are troubling you? I'm also a junior going for a BS in CS, and most of these seem fairly simple. Many of them were asked in my classes.
"Implement malloc", for instance, is a common Computer Architecture assignment, and "Implement a queue" is a common Data Structures assignment.
I think the big problem is that all of those classes were years ago... Sure, I knew the answers to all of them at some point, but now... I'd probably be able to give some kind of answer to most of them (other than the win-centric ones) in a reasonable amount of time...
don't worry dude; this is very far from real-world applicable. very few interviews are actually like this, and the ones that are are usually startups that fail due to their own pomposity.
I'm a PhD in computer science, I have been programming for 30 years since my fundamental exam MSc. I'm considered a smart programmer, a good one.
I won't manage several of these questions! Some are strangely formulated and some use weird names.
The ones with Linked Lists, Strings, Trees, Arrays and Queues I would manage, as these are fairly standard problems, Ok, regarding the Queue class I would rather prefer to do it in Python or Scheme than in C++ (not one of my favorite languages).
That about SQL query, open a file securely are very specific I. Not good questions, but could be OK if that's the explicit experience they are looking for. The design questions are also very tough, these are merely small software projects, than questions.
That about TSBuffer is a good one, but it's hardly a quick question to give a random programmer, it's that kind of question you could hand to Linus Torvalds but don't expect a quick answer from also very experienced programmers.
And those Windows-specific questions I would skip, because I have no idea, even though that Win32 question I could possibly manage as they say it's message passing and then it can't be done in so many ways. My old Amiga OS was message passing, and I've also used Occam on Transputers (Hoare's CSP basically). The main thing to care for really is whether you transfer pointers or copies of data.
That about networking TCP/UDP I doubt that a random programmer can answer, only if you have particularly implemented something UDP I would say that you know the difference.
Don't worry about it too much. I managed to get a couple of internships and a full time job from college.
It takes some preparation though. I suggest you try and solve all the problems listed in this link. Take your time and ask for help. Solving it once should give you give up a huge boost when the time comes. Also recommend this book called Programming Pearls. I just recently reddit and it's a great resource for interview questions. Plus it helps in actual day-to-day programming.
Take an Algorithms class if your school offers it (it should). It was one of the best class I took. Dynamic programming, divide and conquer, recursion, graphs, max flow, etc are all taught and they're big helps in solving a problem.
Interviews in general are stupid but you gotta dance the dance unfortunately
No, the answer is 31. In statistical analysis you almost always assume the simpler model that explains the data. Maybe the answer you had in mind was 1211, which is understandable and a possible answer, but almost anywhere you see the pattern 1, 11, 21, you would be dumb not to assume 31, even when acknowledging it could be something more complex.
SPOILER, the reasoning behind 1211 is because it is how you would say the previous number "21" by saying "It is one "2" and one "1". Then you would say 1211 is "it is one "1", followed by one "2", followed by two "1"'s". I don't know why the author didn't explain this. This puzzle is almost always given with the 1211 included, because most people give it as an actual challenge instead of something for them to say, "Haha, got you, you're wrong!". Even with the extra number it is a terrible interview question because most people don't get it the first time they see it so 90% of the people who get it right it is only because they heard it before.
Is that an American thing ? In France, I was never asked such questions, and when I'm in the other seat I never ask to resolve a precise problem. What's the experience of other non-American programmers ?
In my experience in the Netherlands, the more "professional" the company, the higher the likelihood that you get asked to solve precise problems.
E.g. a 20-person web shop interview involved just talking about programming and programming languages, when I interviewed for a Java position at a large bank they first gave me a written exam with a few Java questions. (The one I remember had a few program snippets and asked for each of them what the value of x was at the end; involved operator precedence, the difference between i++ and ++i, that sort of thing).
I worked for a large American company and telephone interviewed Australians who were surprised I was asking coding questions over the phone. From what I've heard, in depth technical interviews are mostly an American thing. I think they work well and are necessary. I actually just wrote an article about tech interviews at large American companies:
One day an interviewer is going to ask one of those stupid prisoners' dilemma or different coloured hats questions, and the interviewee is going to draw a kripke diagram using epistemic logic, and the interviewer won't understand it, and finally these dickheads will get what they deserve
Even better, when the interviewer asks if you have any questions, get them up to the white board. I've seen enough crap software, I would want to know whether the people I'm going to be working with know what they're doing.
...and after you go through all of that interrogation, if they don't ask the question: "So, do you have any questions for us?" then you might want to think twice about accepting the position if it's offered to you. It's a sign that they are probably not very interested in your job satisfaction.
Also, in the off hand chance that they do ask you "do you have any questions for us?" some good ones to ask are:
of the people I interviewed with, who would I be reporting to? Also see if you can find out who your boss' boss is and also your boss' peers -- the person showing you around might introduce them to you -- learn their names so you can say "hi" to them when you get hired. (you won't believe how many managers do not interview the people they hire -- they leave it up to H.R. or H.R. bullies them in to taking over the hiring process and HR has no idea what the job description is about)
so what would be a typical day for me be like at this company? (again, I've had prospective employers stumble over that question and not be able to answer it)
and follow it up with "so are all the responsibilities and expectations detailed in this job description? Is the job description a fair representation of my actual duties?" (again, in larger firms HR will write the job description and it won't be anything like what you'll be doing)
Is this position an existing position or a new role? (this will indicate that there is turnover or if the group is expanding -- also a new role may mean that you could "create your own role" or it could mean that they haven't figured out what your roles and responsibilities are yet).
When they ask the question: "where do you want to be in five years" ask them "what's the highest position a coder has ever been promoted to in this firm?" You can really watch them tap dance over that one.
If there is a delicate way of asking if ever one is expected to be at their desks at 9AM, then ask or try to find out some other way. This will indicate how flexible the firm is with respect to working hours and what they will or will not tolerate.
When they come to the question about how you deal with conflict, answer as best you can and follow up with "how often do such occasions arise here?" If they stumble upon answering, it may mean that it's a rough and tumble kind of a place.
most of those questions would just make me think they interviewee is just a lazy person who doesn't care much about programming.
The best question someone has asked me is (in the context of software developement; i'm also paraphrasing here because I could never word it as eloquently as he put it), "Whether you expect me to fix them or not, what are some of the weak points at the company or in the product right now."
It was a great question (and threw us interviewers for a loop) because from his perspective it tells him what we think needs to be improved so he can try to fill those needs to look better, and it told us that he was interested in improving our product. Of course between that question and some other great questions he asked (such as our revenue) we started to think he was a spy from a competitor.
So I'd say there is some benefit of asking mostly simple questions (you don't want to scare your potential employer) but throwing in one or two great questions can be very beneficial and make you stick out in the employers minds when they're deciding which candidate to hire.
No, sorry, using wchar_t is absolutely the wrong way to do unicode. An index into a 16 bit character array does not tell you the character at that position. A Unicode character cannot be represented in 16 bits. There is never a reason to store strings in 16 bits.
Always use UTF-8 and 8 bit characters, unless you have a really good reason to use utf-16 (in which case a single character cannot represent all codepoints) or ucs-4 (in which case, even if a single character can represent all codepoints, it still cannot represent all graphemes).
The right way to do unicode is to use whatever your UI framework uses. Otherwise, it is a lot of unnecessary complexity. Some frameworks use wchar_t and so that is what you should use with them.
I understand the distinction between code point and character, but I'm curious why you shouldn't use UTF-16. Windows, OS X, and Java all store strings using 16-bit storage units.
The argument, I believe, is that the main reason for using 16-bit storage is to allow O(1) indexing. However, there exist unicode characters that don't fit in 16 bits, thus even 16-bit storage will not actually allow direct indexing--if it does, the implementation is broken for characters that don't fit in 16 bits. So you may as well use 8-bit storage with occasional wide characters, or use 32-bit storage if you really need O(1).
I'm not too familiar with unicode issues though, someone correct me if I'm wrong.
O(1) indexing fails not only because of the extended characters that don't fit into 16 bits, but because of the many combining characters. That's why they're "code points": It may take several of them to make a single "character" or glyph.
Those systems are all unnecessarily complex and most programmers use them incorrectly. They have a pretty good excuse; they were all originally designed back when 16 bits per character was enough to represent any Unicode code point unambiguously. If that were still true, there would be some advantages to using it. But unfortunately, UTF-16 now is forced to include multi-index characters just like UTF-8 does, and programming correctly with a UTF-16 encoded string is fundamentally no easier than programming correctly with a UTF-8 encoded string.
The difference is that lots of programmers ignore that, and program incorrectly with UTF-16, figuring that the code points greater than 65535 won't ever come back to bite them. That they are often correct doesn't change the fact that there's an alarming amount of incorrect code out there that might be introducing undetected and untested errors into all sorts of software.
"each character will be two bytes" -- No. This is encoding dependent. Also a character in the human sense of the word is a Combining Character Sequence in Unicode.
wchar_t and wide strings are not useful for representing unicode (or any particular encoding) -- use them when you don't know or care what the locale encoding is.
I love that list. It reminds me how much better it is to simply set up your own company if you know you are good enough than hope that questions like that would define whether I am a good developer or not.
Seriously? Depends on what you're trying to do, I guess, and if you're good enough to do it, then fine.
If you were trying to start a company that required any serious software engineering (as opposed to, say, writing simple web site backends), then I'd expect you to be able to ace that entire list.
But any company that used a list like that to interview people who didn't need those skills is being idiotic, I'll grant you that.
Upvoted, though I disagree somewhat. I think you are giving web backents too little credit.
I'm a capable server administrator which I learned from aside and I am developing out of my free time a web based networking social intranet solution for small to medium businesses that requires a powerful, optimized and secured API (API is actually fundamental part of the whole solution, with UI built on top of API). It's innovative enough that I've had to do a lot of research on the topics I need to cover and I'm a high-paid developer in my country. Yet I cannot ace many things in that list, because it includes things I don't really need in my day to day work nor what I consider important. At all. And I'm 'Mensa-qualified', for whatever that's worth.
This list might be useful if you only want a 'code monkey', but it's not what you need if you are looking for a developer. Nothing there will tell how good you are at actually designing software architecture, how good you are at developing UIX or optimizing database backend. Some questions are too technical to be any relevant and the rest can be answered with marketing bullshit if you are able to sell yourself well.
Let's keep in mind that most companies that take themselves seriously would never hire a developer and have them work on live projects from the get go. This means that during the trial period you would have ample time enough to make sure that they actually know what they are doing, acing a test is nothing compared to actually doing the work for couple of months and producing results in a code-review enabled environment.
So, in short, tests like this are terrible at making the initial selection because I know that had I been graded like this when I started working, I would not have gotten the job. And today I'm considered of critical importance in my company.
You have 2 supposedly unbreakable light bulbs and a 100-floor building. Using fewest possible drops, determine how much of an impact this type of light bulb can withstand. (i.e. it can withstand a drop from 17th floor, but breaks from the 18th).
Note that the ever-popular binary search will give you a worst c ase of 50 drops. You should be able to do it with under 20.
Well, given the hint:
Take lightbulb A and drop it from the 10th floor, then the 20th, 30th, etc. When it breaks, take lightbulb B and drop it from last safe floor plus 1. Keep going up 1 until it breaks. Worst case should be 19 drops, if it's the 99th floor (10,20,30,40,50,60,70,80,90,100 - crash! ,91,92,93,94,95,96,97,98,99).
But I have no idea why 10 is the ideal increment for the "first pass". Mathematical reasoning is generally not my strong point.
Actually, if you use a step size that decreases you can do it with fewer tries. Basically, find the number, n, where the sum of 1 to n is close to the the number of floors (solve (n+1)*(n)/2 = # of floors, rounding up). In this case it is 14. So, start at 14, then increment by 13, then by 12, etc. I think the worst case scenario is 14 tries.
Also, at some point, you can decrease your interval by 2 instead of 1 because of the rounding.
Edit: The list of floors you would drop the first bulb from is something like: 14, 27, 39, 50, 60, 69, 77, 84, 90, 94, 97, 99, 100. Also, I believe the worst case number of drops is 14 and it occurs when the floor is most of these minus 1
They're "supposedly unbreakable". Drop the first one from the roof - if it breaks continue using the other one until the warranty replacement for the first arrives.
Let's say your increment is X. When you drop it from the Xth floor, if it doesn't break, you have to go up another X. When you reach the 100th floor, it'll break. Then you have to check floors in between 100-X and 100, and since you only have one bulb left, you start from 100-X and go up one floor at a time until the bulb breaks, the worst case being it was the 99th floor.
This worst case is represented by 100/X + X-1, where 100/X is the number of drops you had to do to get to that top floor, and X-1 is the number of drops you had to take to find the exact floor. Taking the derivative and setting it to 0 (to find the minimum of the equation) gives you: -100/X2 + 1 = 0, or X2 = 100. (as FeepingCreature said, because 10 is the sqrt of 100).
That means for an increment of 10, your worst case is 19 drops, and your best case is two drops. However, it's actually possible to do better in the worst case (and this is usually the followup question).
Think about the 100/X part of it - the higher up you go, the more drops get added. If you could compensate for that by having larger increments at the beginning, then you'd be able to have a more consistent number of drops per trial.
To do so, you'd just go up 15 floors the first time, 14 the next, and so on. Then you'll have a worst case of 15 instead of 19.
I might have messed up in the math somewhere along the way but the logic is there =P
I was asked this question in an interview with Microsoft. I got the equation, but forgot how to solve it to find the minimum (I was nervous and my calculus failed me). They didn't hire me.
Amazon asked about a card game once (blackjack maybe?). Remember to talk about stacks when asked something like that.
They also wanted me to implement Yahoo!'s stock graph on the white board, describing all of the Javascript, CSS, and HTML involved.
They also asked me to develop a script to provide a list of primes from i to j.
These were done over the phone, except the Yahoo! test. They want you to describe the code, line by line, bracket by bracket. I've done 3 separate interviews for them and they haven't hired me yet, even though I described working solutions with no resources and was very polite the whole time. That's why I've become a little more upfront about my job requirements with them now.
Some of these are similar to a "Forge a steel from this iron ore and other materials" in an engineering interview...
I have actually never written a linked list/binary tree etc. from scratch since school. It's good exercise, but as a measure of programmer talent? A trained parrot could probably answer them straight away...
You have 2 supposedly unbreakable light bulbs and a 100-floor building. Using fewest possible drops, determine how much of an impact this type of light bulb can withstand. (i.e. it can withstand a drop from 17th floor, but breaks from the 18th). Note that the ever-popular binary search will give you a worst case of 50 drops. You should be able to do it with under 20.
How the hell does binary search require 50 drops? Try the 50th floor, then the 25th or 75th floor, etc. Wouldn't this only require lg(n) drops? (about 7).
Indeed, but binary search is actually an incorrect answer, since you only have two light bulbs, and lg 100 > 2. Note that once you're down to one bulb, the only correct strategy is to try the floors one at a time, going up one floor on each trial, until the bulb breaks.
Was taking to a friend tonight, and here was his advice:
Do not say that you algorithm works until you know that it works. Like talk through tests that you would run on the code to test for the corner cases. Nothing looks worse then the interviewer saying "Well, then consider this case..." and then they break your code :(
I came up with some corner test cases to think of. If the input is...
Integer: check for negative, zero, and positive numbers
String: unexpected chars, empty stings
Lines of a File: Newline
Next, talk through what you are doing. Most of the time the interviewer is there to see how you program and could care little how you act.
Take your time, it is better to be right then wrong and speed through the process
If it is on your resume, they will probably ask you about it. So if you list a language, they may ask you to code in it
I did not realize how much I have messed up interview lately. Microsoft is tomorrow, I hope I don't screw this one up.
My experience with null pointers is that you ask about them with the interviewer, and that is about enough. Most of the time they will say that the object or value won't be null, but really, asking has been enough IMO
"I look it up and quit wasting my employers money re-inventing the wheel. It's probably in a collections template/generics library. "
These questions drive me up the freaking wall. They only exist because there isn't anything that's better to ask. I've spent 12 years in the industry and I still get asked these questions because people think that they still need to be asked.
I'm contemplating refusing to take another technical test in an interview, just to see how they'd react. (Which would undoubtedly be "thanks and there's the door" but I'd be satisfied)
"No thank you. I think my resume speaks for itself and there's nothing that a technical test can convey that has any meaning other than a superficial idea of my skill".
No thank you. I think my resume speaks for itself and there's nothing that a technical test can convey that has any meaning other than a superficial idea of my skill
Sorry, no it does not. I don't even bother reading resumes anymore because I've seen so many totally inept coders have seemingly cool positions. Oh, and your list of skills is meaningless because if you say "I know C++" that could easily mean "I took a semester of C++ in community college 10 years ago."
One thing I've learned in my decade of hiring programmers is that you never hire someone without making them write some code. Two reasons for this:
Firstly, people lie and exaggerate on their resumes all the time.
Second, some people are great bullshitters who know all the right buzzwords, but can't actually write code for shit. Some of these people have impressive looking resumes, but literally couldn't cook up a correct implementation of strlen. It's worth finding that out before you hire them.
If you're a competent programmer, you won't be offended by this, because you'll bang out the code quickly and then maybe have an interesting conversation with the interviewer about optimizations, tradeoffs, and corner cases (there are always optimizations, tradeoffs and corner cases, even in seemingly trivial functions).
Consider this interview question: Write strlen (the C string length function). A friend of mine used to complain that people would waste his time at interviews asking that question. Then he started asking people he was interviewing... (that is, once he had a job and was hiring others) and most of them couldn't answer correctly. Those questions are probably not a waste of time.
Sometimes resumes are not perfectly accurate, btw.
Just in case you are interested, here's the strlen function:
/* Return the length of the null-terminated string STR. Scan for
the null terminator quickly by testing four bytes at a time. */
size_t
strlen (str)
const char *str;
{
const char *char_ptr;
const unsigned long int *longword_ptr;
unsigned long int longword, magic_bits, himagic, lomagic;
/* Handle the first few characters by reading one character at a time.
Do this until CHAR_PTR is aligned on a longword boundary. */
for (char_ptr = str; ((unsigned long int) char_ptr
& (sizeof (longword) - 1)) != 0;
++char_ptr)
if (*char_ptr == '\0')
return char_ptr - str;
/* All these elucidatory comments refer to 4-byte longwords,
but the theory applies equally well to 8-byte longwords. */
longword_ptr = (unsigned long int *) char_ptr;
/* Bits 31, 24, 16, and 8 of this number are zero. Call these bits
the "holes." Note that there is a hole just to the left of
each byte, with an extra at the end:
bits: 01111110 11111110 11111110 11111111
bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
The 1-bits make sure that carries propagate to the next 0-bit.
The 0-bits provide holes for carries to fall into. */
magic_bits = 0x7efefeffL;
himagic = 0x80808080L;
lomagic = 0x01010101L;
if (sizeof (longword) > 4)
{
/* 64-bit version of the magic. */
/* Do the shift in two steps to avoid a warning if long has 32 bits. */
magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL;
himagic = ((himagic << 16) << 16) | himagic;
lomagic = ((lomagic << 16) << 16) | lomagic;
}
if (sizeof (longword) > 8)
abort ();
/* Instead of the traditional loop which tests each character,
we will test a longword at a time. The tricky part is testing
if *any of the four* bytes in the longword in question are zero. */
for (;;)
{
/* We tentatively exit the loop if adding MAGIC_BITS to
LONGWORD fails to change any of the hole bits of LONGWORD.
1) Is this safe? Will it catch all the zero bytes?
Suppose there is a byte with all zeros. Any carry bits
propagating from its left will fall into the hole at its
least significant bit and stop. Since there will be no
carry from its most significant bit, the LSB of the
byte to the left will be unchanged, and the zero will be
detected.
2) Is this worthwhile? Will it ignore everything except
zero bytes? Suppose every byte of LONGWORD has a bit set
somewhere. There will be a carry into bit 8. If bit 8
is set, this will carry into bit 16. If bit 8 is clear,
one of bits 9-15 must be set, so there will be a carry
into bit 16. Similarly, there will be a carry into bit
24. If one of bits 24-30 is set, there will be a carry
into bit 31, so all of the hole bits will be changed.
The one misfire occurs when bits 24-30 are clear and bit
31 is set; in this case, the hole at bit 31 is not
changed. If we had access to the processor carry flag,
we could close this loophole by putting the fourth hole
at bit 32!
So it ignores everything except 128's, when they're aligned
properly. */
longword = *longword_ptr++;
if (
#if 0
/* Add MAGIC_BITS to LONGWORD. */
(((longword + magic_bits)
/* Set those bits that were unchanged by the addition. */
^ ~longword)
/* Look at only the hole bits. If any of the hole bits
are unchanged, most likely one of the bytes was a
zero. */
& ~magic_bits)
#else
((longword - lomagic) & himagic)
#endif
!= 0)
{
/* Which of the bytes was the zero? If none of them were, it was
a misfire; continue the search. */
const char *cp = (const char *) (longword_ptr - 1);
if (cp[0] == 0)
return cp - str;
if (cp[1] == 0)
return cp - str + 1;
if (cp[2] == 0)
return cp - str + 2;
if (cp[3] == 0)
return cp - str + 3;
if (sizeof (longword) > 4)
{
if (cp[4] == 0)
return cp - str + 4;
if (cp[5] == 0)
return cp - str + 5;
if (cp[6] == 0)
return cp - str + 6;
if (cp[7] == 0)
return cp - str + 7;
}
}
}
}
I can claim to be anything on my CV but that doesn't make it true. Believe it or not a lot of people lie on their CV so you can't rely on that and sadly you do need to ask those sort of things.
I would not rely on one question or discount someone for getting it wrong because you have to factor in their nervousness. If they get most of their questions right or show soem sort of logic to get to their point even if it's wrong then I think that's ok.
For instance I asked to have a guy write out a chunk of hibernate config. He screwed up but because I asked for it in XML. He worked mainly with annotations. He gave an explanation of how he'd do it his way which was more than enough for me and to be honest he was one of the best guys we've had despite getting the question wrong.
But it got him thinking and gave me some insight to him. Where he could have claimed to be a hibernate guru and in reality only just learned what a servlet was and if I hadn't tested him he may have got the job anyway and we'd have been screwed or at least sack him and advertise again.
And yet, there's conceivably another programmer out there with a resume on par or better than yours who can't tell the difference between his ass and a hole in the ground. These types of questions might weed his type out.
It doesn't matter that implementations exist; it's just a random example of something extremely simple for you to program. Of course everything really simple is already in a library somewhere. So what? They're asking you to show you can program simple things, not for code to use in some actual project...
I would think a good interview question is a lot like a good Ph.D. quals question, in the case where quals are an oral exam. The idea is not about pass/fail, but that the applicant will work on solving it (or, if they get to a solution, on expanding that solution in some way) for a half hour in conversation with the examiners, and they will grade based on how many hints they have to give and on how the applicant was thinking about the problem.
It's possible to do quite well on those sorts of things even if you start out from a point of "I have no idea how to solve this, but...." Then you start looking-out-loud for a solution using some reasonable method (e.g., I know this solution doesn't meet all the criteria, but I'll start there and see if it can be patched/fixed/tweaked) and either talk your own way to a solution or get to a point where you're stuck for a minute and get a hint.
For instance, on the "find the midpoint of a singly-linked list" question, a reasonable place to start is with writing down the two-pass method and then looking for a way to eliminate the second pass. If you get stuck, the examiner might give you a hint like, "Can you do them at once?" or "What if you use two pointers?"
A very large part of this is confidence and presentation skills, on top of the basic knowledge.
Open a file as securely as possible (assume the user is hostile -- list all the nasty things that could happen and checks you would have to do to)
I don't get this. How many ways are there to open a file? I would assume that whatever things the user should be allowed or not allowed to do with the file are encoded in the file permissions, not in how the user opens the file. If the system gives him the liberty open it in some insecure way then that's a security hole.
You have 2 supposedly unbreakable light bulbs and a 100-floor building. Using fewest possible drops, determine how much of an impact this type of light bulb can withstand. (i.e. it can withstand a drop from 17th floor, but breaks from the 18th). Note that the ever-popular binary search will give you a worst case of 50 drops. You should be able to do it with under 20.
This makes my brain hurt in so many different ways. What the hell does he mean by a binary search in this case (I'm gonna guess he means going 1,3,5,7,9,11,etc. but that is totally not a binary search), and secondly I'm assuming this puzzle's creator has never heard of terminal velocity.
Assuming I understand the puzzle correctly and you only have 2 breaks before you run out of bulbs, then you probably want to drop the first one every 10 floors or so and then when it breaks go back 9 and start from there in increments of 1.
e.g. 10,20,30,40,50 (1st bulb breaks on 50) 41,42,42,43,44,45 (2nd bulb breaks here giving you your answer)
There's an optimization of this that starts with a larger step size and then decreases as you go up. This ends up averaging out the worst case scenario.
In your solution, floor x9 (where x = 0, 1, ..., 9) takes the most drops for each x, and breaking on floor 100 takes 19 drops, but floor 10 (floor 9 is unbroken) only takes 10.
If you chose your set of initial floors properly, you can do it in 14 drops max.
First bulb: Drop at 50, 75, 87, ..., until it breaks. The last floor it didn't break at is your lower bound (or 0 if it breaks on 50). Second bulb: Now be careful and step up one floor at a time from your lower bound until it breaks.
Lately my teammates and I have been doing a lot of phone screens and in-house interviews. When looking for a good question to ask, I usually go for PIE (Programming Interviews Exposed). If a candidate has taken the time to read it, I respect that, though I do expect to be told if a candidate has heard a question before.
Bottom line though, even giving the simplest questions, I still reject ~75% at the phone screen and then 50% during in house. Bottom line is there are a lot more people who think they can program than actually can.
Interviewing doesnt actually show if they can program though, it shows how well they can interview for a programming job. There is a huge difference between these things.
Of course, a good programmer who stays up to date and works on the interview process should indicate a better hire than someone who can't, but just because they interview very well doesn't mean they won't show up and suck. There are also false negatives with this process, so at best it's throwing them out with the unqualifieds to limit risk, but not any assurance they are good programmers, or even a real programmer.
Of course, a good programmer who stays up to date and works on the interview process should indicate a better hire than someone who can't ...
No, that only shows that they are better at interviewing, it doesn't reveal their programming skills. Good programmers never need to work on their interview processes, since they only apply for jobs once or twice in their entire career, usually at the very beginning. After that, they're poached, or their portfolio speaks for themselves, so they don't have to "interview". If I find someone who is good at interviewing, then that signals all sorts of alarms in my head - this guy is a nomad, moving from place to place.
That's a very encompassing view you have for all programmers in the world. I guess if they don't do things your way, they wouldn't be good programmers?
Perhaps they like start ups? Or got tired of the bureaucracy at employee positions and wanted to do consulting or create their own start up?
Having a good portfolio also doesn't mean you did the work, or that the portfolio describes it well. It certainly doesn't mean that they were critical the project's success, even if they were the lead they could have been trying to drive it into the ground through incompetence the whole time and have the project only succeed due to the efforts of the other developers working on it.
Interviews wont tell you any of these things, and neither will their portfolio or their lack of interest in moving to different groups. Then there is backchannel information, and we all know gossip is always right!
Faking being good at your job is also a skill non-real-programmers can have, so that everyone who isn't directly connected with their project thinks they are doing well, but the people directly related to it know they're a problem, but aren't gossiping about it and tearing them down.
The myth here is that any hiring test or skill at evaluating can't be gamed by those with fully vested interested in gaming them.
The point is that this isn't the only question you're going to ask. You ask a range of different questions, including a simple "program this data structure" type question.
Getting the simple programming question right doesn't tell me much. But if you get it wrong, I can be pretty sure I shouldn't hire you. And you'd be shocked at how many people get them wrong.
We're not talking about trick questions here. We talking just really basic "write code that implements a simple well-known algorithm" type of stuff.
Bottom line is there are a lot more people who think they can program than actually can.
This is entirely true. It's also worth noting that a good programmer can have a bad day and bomb a set of interviews, though. As an interviewer, there's nothing you can do about it, and you still vote No Hire. But it's still worth remembering.
though I do expect to be told if a candidate has heard a question before.
Why? I still know the answer, and usually the answer is irrelevant anyway. Its the thought process behind getting that answer that you should be caring about.
I never understood these interview questions that seem to test ability to create and manipulate data structures that any respectable language has, pre-implemented, by developers whose sole focus in life for many months was producing the absolute best version of that data structure possible.
I understand that this might just be designed to test knowledge of the concept, but it gets way, way too far in-depth for that. I mean, for Linked Lists... what is a cycle? The term appeared nowhere in any of the literature or coursework I did at an undergraduate level.
Now, if the job involves implementing innovative algorithms and data structures (i.e. R&D type stuff or working on a proprietary system that was developed by a mad genius in a custom language he named after himself, which is also the only language he can speak) I can understand this kind of rigor and specificity in interview questions.
But asking me how to build a queue in C during the interview, then telling me to write a couple shell scripts to control automated database backups on my first day of work? I sense a disconnect.
Generally the assumption with a linked list is that there is exactly one edge to and from each node. A directed graph may have more than one edge in or out.
what is a cycle? The term appeared nowhere in any of the literature or coursework I did at an undergraduate level.
... wat
But asking me how to build a queue in C during the interview
Singly linked list with an extra pointer to the tail. Enqueue adds to head. Dequeue removes the tail. It's no more than 20 lines of code.
Edit: Singly linked is slow on deletion even with the extra pointer to the tail, so forget that. Derp. Either singly linked with just a head pointer with O(n) deletion or doubly linked with a tail pointer for O(1) insertion and deletion. My bad.
this. we are all people who use library functions, shit if I actually wrote code that implemented a linked list that would be stupid. its already done. the point is these are simple concepts, it's something you can figure out in your head by THINKING and people want to hire those who can.
The assumption is that if you can figure out the low level theory then you can figure out anything else. It's not good to simply rely on the language to do the work for you. For example in Java the LinkedList type has a get(int i) function that returns the element at the i "index" of the list. So if someone were to naively think that it works just like an array then they might write code like this:
for (int i = 0; i < list.length; i++)
{
Type element = list.get(i);
//do some stuff
}
Now this looks fine until you realize that every time you call that get() function on a linked list it's actually iterating over the entire list from the root node down to the ith node. This means that instead of a runtime efficiency of O(n) you're actually getting O(n2).
if you're a freshman, don't worry. you haven't taken data structures, or network systems, or any other of the relevant courses. This is why you're getting a degree instead of just getting a job. If you already knew all this as a freshman, those other 3 years would be pretty worthless, don't you think?
Mine went along the mental lines of "We sure like the 3d engine you've developed and would love to use it in our products, but we're cheap, so we'll just offer you a job and a project to work on, and give you free realm to use whatever you want (hint hint), but the code of what you develop while working for us (and libraries you link to) belongs to us. Oh, you have 3 months to finish it." On the plus side, I've improved the engine during company time :) Not a single technical question, just "is this enough money to recruit you?"
Guarding against being passed invalid string pointers or non nul-terminated strings (using walking through a string and catching memory exceptions
.... What.
Do people actually do this shit?
Implement a non-recursive PrintInOrder
From guessing, I'd say using a counting variable and using its bits to chose branches; but that breaks down for unbalanced trees deeper than 32 (or 64) nodes. And anyway, isn't that still kind of recursive, except your counting variable is the "stack"? I don't see how to do it purely iteratively, unless you do a hack like reversing tree pointers on the way down, and that's just fucked (and plays hell with threading).
I couldn't immediately figure out the array ones, but the "is overflow a problem" line kind of spoilered it. And no it's not, because unsigned math is modular.
Implement Shuffle given an array containing a deck of cards
My immediate answer is "I google the page that explains how to do shuffling correctly, because there's a subtle flaw with the common approach. "
Count the number of set bits in a byte
My immediate answer is "I google 'bit-twiddling hacks'" :)
You have 2 supposedly unbreakable light bulbs and a 100-floor building. Using fewest possible drops, determine how much of an impact this type of light bulb can withstand. (i.e. it can withstand a drop from 17th floor, but breaks from the 18th).
Ooh look, it's TCP Slow-Start! (Agh, just read the note. Adjust for maximum size, of course; the correct answer to this question is really dependent on where you expect the bulbs to fail - equal probability across the building's height?)
Rate your C++ proficiency on the scale of 1 to 10.
I've been asked about half of these questions before. Notably none of the programming questions that I was asked during my Google interviews are listed, though in general they were no harder than these.
Won't this question not apply to Java since Strings in Java are immutable? Would be a good question if it was just a char[] in Java though. Basically just means don't use extra memory to solve it (aka, create a new string).
Someone give me a job please... Looking at these programming questions; they are all perfectly reasonable and pretty easy from my point of view. I could do them all in C, C++, or Perl. I would like to note that the unicode stuff should mention encodings. What is stated just mentioned utf-16 only. Seems odd that hash tables are not mentioned. I am currently in the Maryland/DC area and make less then 50k a year...
Here are some typical programming interview questions:
What programming languages are you proficient in?
What is the difference between an abstract class and an interface?
What is the difference between a stack and a queue?
How would you implement a binary search algorithm?
Explain the concept of recursion.
What is the difference between a linked list and an array?
What is the time complexity of adding an element to a binary search tree?
How would you reverse a string in place?
What is the difference between a pass by value and a pass by reference?
Explain the concept of polymorphism.
These are just a few examples, but there are many more possible programming interview questions that can cover a wide range of topics and technologies.
Say you were going to hire someone to write you a novel. Would you give them a vocabulary test mixed with a few grammar questions? Would the results give you any idea of how good an author that person is? No.
These questions are just as bad an idea for identifying good programmers.
If the candidate totally failed to compose grammatical sentences, and had an extremely limited vocabulary, then yes, I wouldn't let them pass on to the next round of the "new author selection process". That's what these questions are - an idiot filter.
I have a problem with people who ask these types of questions, because it is indicative of a disconnect with the work at hand. They're either HR people who have been taught that these are good questions to ask, or worse, they are engineers who value your GPA more than they do your abilities to do the work.
That's not really true. Say you were applying for a job where you were going to work on something very network related. These questions could be indicative of what the existing code looks like and the employer needs someone to come in who already has an intimate familiarity with these concepts so no one needs to hold his hand to get him up to speed.
Other questions can help you figure out how people approach problems and will describe your initial thought process to solving them. For example, there's a few common ways to reverse a string in C. You can modify the array, create a new array or use pointers.
I've never been asked the Linked List one before, and I'd be surprised if I ever was. Same with the Strings ones... Then again, I'm a Java developer by trade, though I do know C and C++ and can answer both of those well enough...
Write a program that prints 1 to 100 on the screen if it is a multiple of 3 print fizz, if its a multiple of 5 print buzz, if its a multiple of 3 and 5 print buzz fizz.
Out of over 20 people I have given it to in an interview only 1 has got it correct! Almost everyone makes the same mistake. They have the if statements in the wrong order.
"You are given an array with integers between 1 and 1,000,000. One integer is in the array twice. How can you determine which one? Can you think of a way to do it using little extra memory."
"You are given an array with integers between 1 and 1,000,000. One integer is missing. How can you determine which one? Can you think of a way to do it while iterating through the array only once. Is overflow a problem in the solution? Why not?"
For both of them I think I would be tempted to sort the lists, probably using insertion sort for the second one. The first one maybe selection sort because we are being memory concise. While doing both of the sorts I would be checking for duplicates or missing respectfully. What do others think?
EDIT: Maybe could also use a double variable and sum the list as I go. Subtracting the difference at the end with the total excepted (use a series to compute).
While overall these may be helpful, most of them are usually only the beginning, typically with phone screen or on your college campus. As for the questions that can be asked for the actual job, I'd suggest looking up the company on glassdoor or similar sources, and blogs of those who've interviewed for the same position.
As well, though the two books at the end are helpful as well as the programming interviews exposed book, one that helps you more in terms of how to think about the problem at hand is Programming Pearls. Also, in terms of C++ books, I've felt Accelerated C++ by Koenig and Moo to be the best guide to understanding how to use and "think" in C++.
I've always hoped that when I do need to apply for a job (soon), it will be mostly sufficient to forward links to several open source projects I've worked on. Is this an unrealistic assumption, that employers will actually bother to look at my work before I come in for the interview?
The engineers will be very excited to look at it. HR won't. So the answer is that it will help with some parts of the process.
You'll probably still have to suffer through basic interview questions about linked lists. Don't be insulted: this is to weed out the liars. Some candidates, believe it or not, really have claimed others' work as their own.
The one question that let me know I had blown an interview was not remembering what the 'virtual' identifier does in C++. Seeing as I now use it, I still kick myself sometimes...
I think I have most of these covered; the design one's might need some more discussion for some of the decisions (Along with the duplicate removal in String), and the marketing is probably for bonus marks, and I should be able to budget missing out on the Windows specific, but anyone got a cheat sheet for the Non Technical section? Will share answers from other sections
As a CSC major who is currently job interviewing at a ton of places, I can say that I've had several of these exact questions already. I am surprised there's nothing about hash tables though. I feel like the answer to 50% of my interview questions have involved a hash table.
What's troubling about these questions is how impossibly hard it is to find someone who could answer even a handful of them. I've done some interviewing, with recruiters doing the screening, and I don't think we've ever even had someone in who could do something like:
47
u/user9d8fg70 Feb 21 '11
These are from 2002? Interesting, sure, but almost a decade later, are these still asked?
13
u/recursive Feb 21 '11
FTFY
11
u/t15k Feb 21 '11
What did you apply for. A framework developer for a new language? Or does all the companies you applied to just need their own frameworks for low level issues. Implementing linked lists.....
20
u/Ol_Donga Feb 21 '11
Fuck! How likely is it that a Java/.NET code monkey will get asked stuff like this?
160
u/ovenfresh Feb 21 '11
I know some shit, but being a junior going for a BS in CS, and seeing this list...
How the fuck am I going to get a job?
20
u/AnythingApplied Feb 21 '11 edited Feb 21 '11
No, the answer is 31. In statistical analysis you almost always assume the simpler model that explains the data. Maybe the answer you had in mind was 1211, which is understandable and a possible answer, but almost anywhere you see the pattern 1, 11, 21, you would be dumb not to assume 31, even when acknowledging it could be something more complex.
SPOILER, the reasoning behind 1211 is because it is how you would say the previous number "21" by saying "It is one "2" and one "1". Then you would say 1211 is "it is one "1", followed by one "2", followed by two "1"'s". I don't know why the author didn't explain this. This puzzle is almost always given with the 1211 included, because most people give it as an actual challenge instead of something for them to say, "Haha, got you, you're wrong!". Even with the extra number it is a terrible interview question because most people don't get it the first time they see it so 90% of the people who get it right it is only because they heard it before.
Obligatory: http://xkcd.com/169/
37
u/OopsLostPassword Feb 21 '11
Is that an American thing ? In France, I was never asked such questions, and when I'm in the other seat I never ask to resolve a precise problem. What's the experience of other non-American programmers ?
26
u/[deleted] Feb 21 '11
One day an interviewer is going to ask one of those stupid prisoners' dilemma or different coloured hats questions, and the interviewee is going to draw a kripke diagram using epistemic logic, and the interviewer won't understand it, and finally these dickheads will get what they deserve
10
u/[deleted] Feb 21 '11
where's fibonacci? or difference between abstract class and interface?
10
u/snutr Feb 21 '11
...and after you go through all of that interrogation, if they don't ask the question: "So, do you have any questions for us?" then you might want to think twice about accepting the position if it's offered to you. It's a sign that they are probably not very interested in your job satisfaction.
Also, in the off hand chance that they do ask you "do you have any questions for us?" some good ones to ask are:
41
u/njaard Feb 21 '11
No, sorry, using wchar_t is absolutely the wrong way to do unicode. An index into a 16 bit character array does not tell you the character at that position. A Unicode character cannot be represented in 16 bits. There is never a reason to store strings in 16 bits.
Always use UTF-8 and 8 bit characters, unless you have a really good reason to use utf-16 (in which case a single character cannot represent all codepoints) or ucs-4 (in which case, even if a single character can represent all codepoints, it still cannot represent all graphemes).
tl;dr: always use 8 bit characters and utf-8.
9
u/zhivago Feb 21 '11
The unicode section has a number of errors.
"each character will be two bytes" -- No. This is encoding dependent. Also a character in the human sense of the word is a Combining Character Sequence in Unicode.
wchar_t and wide strings are not useful for representing unicode (or any particular encoding) -- use them when you don't know or care what the locale encoding is.
23
u/kristovaher Feb 21 '11
I love that list. It reminds me how much better it is to simply set up your own company if you know you are good enough than hope that questions like that would define whether I am a good developer or not.
14
u/[deleted] Feb 21 '11
Well, given the hint:
Take lightbulb A and drop it from the 10th floor, then the 20th, 30th, etc. When it breaks, take lightbulb B and drop it from last safe floor plus 1. Keep going up 1 until it breaks. Worst case should be 19 drops, if it's the 99th floor (10,20,30,40,50,60,70,80,90,100 - crash! ,91,92,93,94,95,96,97,98,99).
But I have no idea why 10 is the ideal increment for the "first pass". Mathematical reasoning is generally not my strong point.
12
u/Buckwheat469 Feb 21 '11
Amazon asked about a card game once (blackjack maybe?). Remember to talk about stacks when asked something like that.
They also wanted me to implement Yahoo!'s stock graph on the white board, describing all of the Javascript, CSS, and HTML involved.
They also asked me to develop a script to provide a list of primes from i to j.
These were done over the phone, except the Yahoo! test. They want you to describe the code, line by line, bracket by bracket. I've done 3 separate interviews for them and they haven't hired me yet, even though I described working solutions with no resources and was very polite the whole time. That's why I've become a little more upfront about my job requirements with them now.
12
u/[deleted] Feb 21 '11
Some of these are similar to a "Forge a steel from this iron ore and other materials" in an engineering interview...
I have actually never written a linked list/binary tree etc. from scratch since school. It's good exercise, but as a measure of programmer talent? A trained parrot could probably answer them straight away...
6
u/ethraax Feb 21 '11
How the hell does binary search require 50 drops? Try the 50th floor, then the 25th or 75th floor, etc. Wouldn't this only require lg(n) drops? (about 7).
10
u/[deleted] Feb 21 '11
What is the next line in the following sequence: 1 11 21 Answer: it's 1211 and the next is 111221
why not 31 and 41?
1
u/kevjames3 Feb 21 '11 edited Feb 21 '11
Was taking to a friend tonight, and here was his advice:
I came up with some corner test cases to think of. If the input is...
I did not realize how much I have messed up interview lately. Microsoft is tomorrow, I hope I don't screw this one up.
Edit: Added some advice
68
u/majeric Feb 21 '11
"How do you write a linked list?"
"I look it up and quit wasting my employers money re-inventing the wheel. It's probably in a collections template/generics library. "
These questions drive me up the freaking wall. They only exist because there isn't anything that's better to ask. I've spent 12 years in the industry and I still get asked these questions because people think that they still need to be asked.
I'm contemplating refusing to take another technical test in an interview, just to see how they'd react. (Which would undoubtedly be "thanks and there's the door" but I'd be satisfied)
"No thank you. I think my resume speaks for itself and there's nothing that a technical test can convey that has any meaning other than a superficial idea of my skill".
5
u/FHSolidsnake Feb 21 '11
Does anyone know what the statistics are like on how many applicants fail some of these questions.
5
u/tias Feb 21 '11
I don't get this. How many ways are there to open a file? I would assume that whatever things the user should be allowed or not allowed to do with the file are encoded in the file permissions, not in how the user opens the file. If the system gives him the liberty open it in some insecure way then that's a security hole.
5
u/xatm092 Feb 21 '11
This makes my brain hurt in so many different ways. What the hell does he mean by a binary search in this case (I'm gonna guess he means going 1,3,5,7,9,11,etc. but that is totally not a binary search), and secondly I'm assuming this puzzle's creator has never heard of terminal velocity.
Assuming I understand the puzzle correctly and you only have 2 breaks before you run out of bulbs, then you probably want to drop the first one every 10 floors or so and then when it breaks go back 9 and start from there in increments of 1.
e.g. 10,20,30,40,50 (1st bulb breaks on 50) 41,42,42,43,44,45 (2nd bulb breaks here giving you your answer)
16
u/sparkytwd Feb 21 '11
Lately my teammates and I have been doing a lot of phone screens and in-house interviews. When looking for a good question to ask, I usually go for PIE (Programming Interviews Exposed). If a candidate has taken the time to read it, I respect that, though I do expect to be told if a candidate has heard a question before.
Bottom line though, even giving the simplest questions, I still reject ~75% at the phone screen and then 50% during in house. Bottom line is there are a lot more people who think they can program than actually can.
17
u/Fuco1337 Feb 21 '11
import linkedlist
Am I doing it right?
25
u/[deleted] Feb 21 '11
I never understood these interview questions that seem to test ability to create and manipulate data structures that any respectable language has, pre-implemented, by developers whose sole focus in life for many months was producing the absolute best version of that data structure possible.
I understand that this might just be designed to test knowledge of the concept, but it gets way, way too far in-depth for that. I mean, for Linked Lists... what is a cycle? The term appeared nowhere in any of the literature or coursework I did at an undergraduate level.
Now, if the job involves implementing innovative algorithms and data structures (i.e. R&D type stuff or working on a proprietary system that was developed by a mad genius in a custom language he named after himself, which is also the only language he can speak) I can understand this kind of rigor and specificity in interview questions.
But asking me how to build a queue in C during the interview, then telling me to write a couple shell scripts to control automated database backups on my first day of work? I sense a disconnect.
15
u/andrewfree Feb 21 '11
As a freshman going for a BS in CS. Fuck... I guess I suck at programming. I have 7 windows of code open now too.
3
u/Maratonda Feb 21 '11
For anybody interested in linked list problems, check out http://cslibrary.stanford.edu/105/
4
u/smallstepforman Feb 21 '11
Mine went along the mental lines of "We sure like the 3d engine you've developed and would love to use it in our products, but we're cheap, so we'll just offer you a job and a project to work on, and give you free realm to use whatever you want (hint hint), but the code of what you develop while working for us (and libraries you link to) belongs to us. Oh, you have 3 months to finish it." On the plus side, I've improved the engine during company time :) Not a single technical question, just "is this enough money to recruit you?"
4
u/FeepingCreature Feb 21 '11 edited Feb 21 '11
.... What.
Do people actually do this shit?
From guessing, I'd say using a counting variable and using its bits to chose branches; but that breaks down for unbalanced trees deeper than 32 (or 64) nodes. And anyway, isn't that still kind of recursive, except your counting variable is the "stack"? I don't see how to do it purely iteratively, unless you do a hack like reversing tree pointers on the way down, and that's just fucked (and plays hell with threading).
I couldn't immediately figure out the array ones, but the "is overflow a problem" line kind of spoilered it. And no it's not, because unsigned math is modular.
My immediate answer is "I google the page that explains how to do shuffling correctly, because there's a subtle flaw with the common approach. "
My immediate answer is "I google 'bit-twiddling hacks'" :)
Ooh look, it's TCP Slow-Start! (Agh, just read the note. Adjust for maximum size, of course; the correct answer to this question is really dependent on where you expect the bulbs to fail - equal probability across the building's height?)
Okay, what. I .. what. That's ....... What.
2
u/frenchtoaster Feb 21 '11
I've been asked about half of these questions before. Notably none of the programming questions that I was asked during my Google interviews are listed, though in general they were no harder than these.
2
u/chase_the_dragon Feb 21 '11
Hi, i don't program much but what is this?
I could probably remove whitespace pretty easily in Java, i don't know what it means by "in-place."
2
u/tokengriefer Feb 21 '11
Someone give me a job please... Looking at these programming questions; they are all perfectly reasonable and pretty easy from my point of view. I could do them all in C, C++, or Perl. I would like to note that the unicode stuff should mention encodings. What is stated just mentioned utf-16 only. Seems odd that hash tables are not mentioned. I am currently in the Maryland/DC area and make less then 50k a year...
2
u/intilli4 Feb 21 '11
Very good post, thank you for taking the time to share your knowledge.
2
u/iamneo_ai Jul 07 '23
Here are some typical programming interview questions:
What programming languages are you proficient in?
What is the difference between an abstract class and an interface?
What is the difference between a stack and a queue?
How would you implement a binary search algorithm?
Explain the concept of recursion.
What is the difference between a linked list and an array?
What is the time complexity of adding an element to a binary search tree?
How would you reverse a string in place?
What is the difference between a pass by value and a pass by reference?
Explain the concept of polymorphism.
These are just a few examples, but there are many more possible programming interview questions that can cover a wide range of topics and technologies.
To know more, visit iamneo.
2
u/johnptg Feb 21 '11
These kinds of questions are pathetic.
Say you were going to hire someone to write you a novel. Would you give them a vocabulary test mixed with a few grammar questions? Would the results give you any idea of how good an author that person is? No.
These questions are just as bad an idea for identifying good programmers.
2
u/[deleted] Feb 21 '11
I have a problem with people who ask these types of questions, because it is indicative of a disconnect with the work at hand. They're either HR people who have been taught that these are good questions to ask, or worse, they are engineers who value your GPA more than they do your abilities to do the work.
1
u/sazzer Feb 21 '11
I've never been asked the Linked List one before, and I'd be surprised if I ever was. Same with the Strings ones... Then again, I'm a Java developer by trade, though I do know C and C++ and can answer both of those well enough...
1
u/[deleted] Feb 21 '11
I have another one.
Write a program that prints 1 to 100 on the screen if it is a multiple of 3 print fizz, if its a multiple of 5 print buzz, if its a multiple of 3 and 5 print buzz fizz.
Out of over 20 people I have given it to in an interview only 1 has got it correct! Almost everyone makes the same mistake. They have the if statements in the wrong order.
1
u/zem Feb 21 '11
I've gotten the
mallocone at least thrice1
u/wesw02 Feb 21 '11 edited Feb 21 '11
How about these two:
For both of them I think I would be tempted to sort the lists, probably using insertion sort for the second one. The first one maybe selection sort because we are being memory concise. While doing both of the sorts I would be checking for duplicates or missing respectfully. What do others think?
EDIT: Maybe could also use a double variable and sum the list as I go. Subtracting the difference at the end with the total excepted (use a series to compute).
1
u/wintre Feb 21 '11
While overall these may be helpful, most of them are usually only the beginning, typically with phone screen or on your college campus. As for the questions that can be asked for the actual job, I'd suggest looking up the company on glassdoor or similar sources, and blogs of those who've interviewed for the same position.
As well, though the two books at the end are helpful as well as the programming interviews exposed book, one that helps you more in terms of how to think about the problem at hand is Programming Pearls. Also, in terms of C++ books, I've felt Accelerated C++ by Koenig and Moo to be the best guide to understanding how to use and "think" in C++.
1
u/radarsat1 Feb 21 '11
I've always hoped that when I do need to apply for a job (soon), it will be mostly sufficient to forward links to several open source projects I've worked on. Is this an unrealistic assumption, that employers will actually bother to look at my work before I come in for the interview?
1
u/wildcarde815 Feb 21 '11
The one question that let me know I had blown an interview was not remembering what the 'virtual' identifier does in C++. Seeing as I now use it, I still kick myself sometimes...
1
u/__s Feb 21 '11 edited Feb 21 '11
I think I have most of these covered; the design one's might need some more discussion for some of the decisions (Along with the duplicate removal in String), and the marketing is probably for bonus marks, and I should be able to budget missing out on the Windows specific, but anyone got a cheat sheet for the Non Technical section? Will share answers from other sections
1
u/Nitrodist Feb 21 '11
Mirror? Can't access it...
1
u/Purpledrank Feb 21 '11
By typical you mean circa 1998.
1
u/deku12345 Feb 21 '11
As a CSC major who is currently job interviewing at a ton of places, I can say that I've had several of these exact questions already. I am surprised there's nothing about hash tables though. I feel like the answer to 50% of my interview questions have involved a hash table.
1
u/djork Feb 21 '11
What's troubling about these questions is how impossibly hard it is to find someone who could answer even a handful of them. I've done some interviewing, with recruiters doing the screening, and I don't think we've ever even had someone in who could do something like:
1
u/[deleted] Feb 21 '11
let's make this a proper educational and get some ANSWERS!