Live data from Hacker News

Computer Science Interview Questions with C++ Solutions

grokit.ca

51–60 of 73 posts

Re: Computer Science Interview Questions with C++ Solutions

#51

I have a question, I consider myself a great software developer with a proven track record. I have open source code, lots of completed and shipped websites and software. Do interviewers really care about this sort of interview knowledge outside of the San Fransisco start up bubble? I've been programming and making a great living for more than 8 years now, and not once did I have to implement a b-list tree or somethin…

As I said here in https://news.ycombinator.com/item?id=6950242 : Similarly, effortless recall of the pros and cons of different algorithms and data-structures means that you don't have to think twice about many of the things that should be purely mechanical. It then lets you recognize things when they show up in disguise, and to concentrate on the higher level work, where the real work begins. And here in https://new…

Good point regarding getting things done. I would add to that list that the things should work.

Re: Computer Science Interview Questions with C++ Solutions

#52
post #16

Earlier quoted context omitted.

Agree on needing comments. My C++ is a bit rusty, but I think the code is in fact checking if the number is divisible by 2 (i.e. n % 2 == 0). I think it's using the bitwise and operator (single &) to AND each bit in n and (n-1) and then checking if the least significant bit is 1 or 0. The code would need to shift ( >) to check if the number were a power of 2. I thought there was another bitwise NOT operator, not the…

The GP is correct, this is bit-twiddling code to test for a single bit being set in the int, and therefore being a power of 2, not simply a multiple of 2. Broadly speaking, and ignoring edge cases, if N is a power of 2 then it has a single bit set. Subtracting one unsets that bit, so the AND of N and (N-1) is zero. On the other hand, if N is not a power of two then subtracting 1 leaves the top bit still set, so the A…

Thanks, you're right. I don't know why I would have ever thought "!" was bitwise... only on a Saturday night.

It just goes to show that sleep is very important for interviews!

Re: Computer Science Interview Questions with C++ Solutions

#53

Earlier quoted context omitted.

Maybe they're not commonly used in interviews because too few people refuse to take the sort of interviews where they wouldn't be allowed?

having trouble following your nested negative set logic sentence structure here.

Restructured: "Maybe they're not commonly used in interviews because too few people insist on being able to use them in interviews?"

Re: Computer Science Interview Questions with C++ Solutions

#54
post #43

Earlier quoted context omitted.

Personally, I'd walk out of an interview if they started asking me these types of questions. Unless of course, if it's a job where it'd be very algorithm-heavy to begin with, but that isn't where my interest lies.

I don't understand this attitude. There must be lots of great companies to work at where the interview process is a bit flawed and the questions a bit unrealistic. Why let that stop you? Why handicap yourself when you can just learn it?

because apparently parts of america are an insane sellers market where you can command 100k+ fresh out of school. If you don't want to deal with these questions there's ten more jobs down the street that won't ask you any hard questions.

Re: Computer Science Interview Questions with C++ Solutions

#55

I'm surprised, in an industry that is founded upon automating repetitive tasks, that the coding interview can't be automated. Isn't that what standardized testing is all about?

This comment nails it:

  > I really don't find these questions to be useful indicators
  > of the things that make-up a good software engineer.  I am
  > using "software engineer" here on purpose and as something
  > distinct from "programmer" or "coder".

  > One will design and develop good reliable products that are
  > maintainable and extensible.  The other will just crank out
  > code and is likely to not really add value beyond that.

  > I want to know how a person thinks and reasons, how good he
  > or she is about data representation or the formulation and
  > communication of a strategy in creating a solution.  I want
  > to know how a person thinks at the abstract, code, project
  > and product levels.
https://news.ycombinator.com/item?id=6942548

Standardized testing will quickly get subverted, with people "studying for the test." It's almost a theorem that any proxy for assessment will become subverted, with people passing the test without actually possessing the necessary underlying skill. In math people keep complaining about "teaching to the test" and that people pass the tests, and yet don't have the skills.

Same will happen if you try to standardize computer recruitment.

Re: Computer Science Interview Questions with C++ Solutions

#57

I have a question, I consider myself a great software developer with a proven track record. I have open source code, lots of completed and shipped websites and software. Do interviewers really care about this sort of interview knowledge outside of the San Fransisco start up bubble? I've been programming and making a great living for more than 8 years now, and not once did I have to implement a b-list tree or somethin…

I'm outside the SF startup bubble, and I interview a lot of mostly recent college grads. I like to ask theoretical questions, especially of college grads. It's not because I expect that they'll need hard CS skills, but it's because I want to know the following things:

Can they effectively break down a hard problem into sub-problems? Can they compare the difficulty of sub-problems and prioritize? Can they, while working on one sub-problem, think about the effects that their solution will have on the other parts of the problem? Can they keep track of the big picture of what they're trying to solve while working on a small part of it? Can they translate their ideas into code fluently? Can they adapt to change and fix their system cleanly? Are they interested in computing? Have they spent their own time on learning?

These are not theoretical results - these are the qualities that make or break an entry-level engineer. I ask formal CS questions because formal CS is a context that the candidates should be comfortable in, and thus I can ask a hard question quickly. However, I'm far more interested in the meta-questions than if they can get through the solution to Problem X.

I try to avoid measuring a candidate with a single question: if I'm doing a phone interview, I'll try to hit many areas (I'm sure you're familiar with Steve Yegge's post on phone screens), so the formal CS part is rarely more than 20 minutes. On the other hand, for an on-site interview, we tend to each focus on specific areas, so I can happily spend an entire hour on one or two hard theoretical questions (if I get to cover the algorithms/data structures section).

So - your mileage may vary, and given that you have a significant track record, I don't think that hard theoretical questions would be the best way to measure your ability. But for some categories of candidate (mostly recent college grads), I think that formal CS questions are a good meterstick.

(Edited for formatting)

Re: Computer Science Interview Questions with C++ Solutions

#58
post #56
post #25

> Implement a simple linked list in C (not C++). It can be compiled on a C++ compiler, but do not use any feature of C++. Er, which standard of C?

You get the job if you can think of a non-trivial way in which in matters.

That's pretty easy. Pre-C89 did not have void pointers, thus a generic linked list would have to use char pointers.

Beyond the wrong-ness of using an incorrect dereferencer type you would also force any users of your linked list to make an explicit cast. Meanwhile a post-C89 linked list could return void *. Thus taking advantage of C's implicit cast of void pointers.

Meanwhile if you compiled this second void pointer returning linked list under a C++ compiler would have to make an explicit cast just like in the pre-C89 case.

Re: Computer Science Interview Questions with C++ Solutions

#59

Earlier quoted context omitted.

Personally, I'd walk out of an interview if they started asking me these types of questions. Unless of course, if it's a job where it'd be very algorithm-heavy to begin with, but that isn't where my interest lies.

That's your right (of course) and I have no argument with it. But let me offer another point of view. To my mind, the point isn't whether or not the job is algorithm-heavy. If you don't have this stuff under your belt, there are limits to what you can do. If you have to concentrate on working out which algorithm to use, or which data structure to use, if you have to spend time researching these things, that doesn't m…

So what do you think is an effective way to interview for a person's ability to get things done?

Re: Computer Science Interview Questions with C++ Solutions

#60

Earlier quoted context omitted.

That's your right (of course) and I have no argument with it. But let me offer another point of view. To my mind, the point isn't whether or not the job is algorithm-heavy. If you don't have this stuff under your belt, there are limits to what you can do. If you have to concentrate on working out which algorithm to use, or which data structure to use, if you have to spend time researching these things, that doesn't m…

So what do you think is an effective way to interview for a person's ability to get things done?

I don't know, but if you hunt through my comments on HN you'll see what I do. Mostly it seems to have been successful - the guys on my teams are pretty good. Mostly I've only gone wrong when I've put too much faith in paper qualifications.

I ask people to code something trivial, on a whiteboard, in any pseudo-code they care to invent on the spot. Then we talk about the strengths and weaknesses of the code they wrote. We end up talking about algorithms, data structures, project management, quick hacks, technical debt, comments, function and method size, functional programming, and more.

The idea is to find their strengths, to make sure their weaknesses are covered by people we already have, and to see if we could work together. Sometimes we don't even agree, and it's the way they discuss the points that matters.

I'd love to see it made into a science, but I'm nowhere near clever enough to do that.

Post reply on HN