Live data from Hacker News

Interviewing programmers: coding test example explained

solipsys.co.uk

41–50 of 178 posts

Re: Interviewing programmers: coding test example explained

#41
post #36

Earlier quoted context omitted.

Why would he be alone? Why is spelling less important in code than in normal writing? I would argue it is considerably more important.

If you truly think the market for C developers is so favorable to employers that someone who can write the in-place-whitespace-removal function off the top of their heads is easy to find, then by all means, ding candidates for their spelling during interviews. Thanks for making it that much easier for the rest of us to hire. In the industry I work in --- computer software --- it is ludicrously hard to find people com…

This is not a simple misspelling though. If someone would write 'int countar = 0;' because he doesn't speak English well or whatever, that's fine. But spelling 'write' as 'rite' is indicative of a certain mindset - of favoring a certain quirky sense of beauty or style over clarity. And I didn't say it'd be autoding, just that it lowers my opinion of the author a bit. If the rest was OK that would be noise in between all the other criteria.

Re: Interviewing programmers: coding test example explained

#42

Earlier quoted context omitted.

Currently working on that. It's safe to say that your two solutions were the most creative. In my graph of solution proximity, they are both a long way away from all the other solutions.

Awww. I was hoping that with an audience of hackers and such a trivial problem I wouldn't be alone in my creativity. :-/

If you want 'creative' solutions to problems you might want to check out google code jam archives. During the qualifications this year someone wrote a solution in lolcode. Was quite interesting.

Re: Interviewing programmers: coding test example explained

#43
post #36

Earlier quoted context omitted.

Why would he be alone? Why is spelling less important in code than in normal writing? I would argue it is considerably more important.

If you truly think the market for C developers is so favorable to employers that someone who can write the in-place-whitespace-removal function off the top of their heads is easy to find, then by all means, ding candidates for their spelling during interviews. Thanks for making it that much easier for the rest of us to hire. In the industry I work in --- computer software --- it is ludicrously hard to find people com…

I think you exaggerate. If you actually look at advertisements for c/c++ developers, they tend to contain words to the effect, "Must have 4-5 years experience in high speed algorithmic trading", etc. But if you know any good-paying jobs that only require the skill level you suggest, point me in that direction. (I mean that--I can get away from my current huge and horrible codebase. Speaking of which, I remember being appalled by the consistently awful misspelling of virtually everything until someone pointed out that its DOS origins required 8 character limits on filenames. I suspect such charming beasts as atoi and strlen had similar constraints, if only for purposes of saving RAM on PDP 11s.)

Re: Interviewing programmers: coding test example explained

#44
I got this exact same question in a Google on-site interview. It was one of those warm-ups :)

It does require someone to think like a C programmer: handling buffers directly, in-place modification and using NULL terminators to end strings that may have memory allocated beyond the NULL. I think it's a great question, but I don't know how well it would go over with CS undergrad students coming out with a Java only background.

Should I look for an equivalent simplistic Java question or stick to the guns and require candidates to know C? (I know the answer for my own team, but curious on others thoughts)

Re: Interviewing programmers: coding test example explained

#45

I'm nowhere near an experience C coder, but doesn't the in place part mean that you don't create any additional variables or strings and just modify z_terminated? Is that even possible? This is an honest question, because the solution is obvious this way, but a bit harder if you can't create additional variables.

"In place" usually means that the result is in the same place as the input, and you don't create an intermediate copy. Creating a fix, known number of additional variables to assist with the calculation is OK. Some people allocated memory, copied out the input, then put back the bits they wanted to keep. That is not "in place".

Your routine should modify the given zero-terminated string in place, removing all instances of the given char.

The main point of the whole exercise is to see if the candidate can write any code - anything after that is a bonus.

Now if the input and output of a function are correct I think you where simply less clear than you may have thought. If you had said "string in place (don't allocate any memory)," I suspect far more people would have given you the output you wanted.

Re: Interviewing programmers: coding test example explained

#46
post #45

Earlier quoted context omitted.

"In place" usually means that the result is in the same place as the input, and you don't create an intermediate copy. Creating a fix, known number of additional variables to assist with the calculation is OK. Some people allocated memory, copied out the input, then put back the bits they wanted to keep. That is not "in place".

Your routine should modify the given zero-terminated string in place, removing all instances of the given char. The main point of the whole exercise is to see if the candidate can write any code - anything after that is a bonus. Now if the input and output of a function are correct I think you where simply less clear than you may have thought. If you had said "string in place (don't allocate any memory), " I suspect…

[deleted]

Re: Interviewing programmers: coding test example explained

#48
post #17

Earlier quoted context omitted.

Yes, C strings are \0 terminated and that is what you'd end up with. Memory management is between you, malloc() and free(). Assuming this were malloc()d memory, if you wanted to free up the unused bytes, you'd probably: char *condensed = strdup(z_terminated); if (condensed) free(z_terminated); else // out of memory

Using realloc would be better, since it allows the memory allocator the option of not copying the string.

Indeed. I wasn't sure you could realloc to a smaller block. Good to know.

Re: Interviewing programmers: coding test example explained

#50

I'm sure RiderOfGiraffes doesn't want a third entry from me at this point, so I figure I might as well just post it here: #define C char #define F for #define R condense_by_removing #define V void V R(C*A,C B){F(C*J=A;*J=*A++;J+=*J!=B);} or without #defines: void condense_by_removing(char*A,char B){for(char*J=A;*J=*A++;J+=*J!=B);}

Here is the same code, without syntactic obfuscation:

  void condense_by_removing(char* s, char c)
  {
    char* d = s;
    while (*d = *s++)
      d += *d != c;
  }
I would have sworn I found a bug. There is none. Brilliant.

Now, I wonder if we could further optimize it. For instance by accessing memory several bytes at a time, in a fashion similar to strcmp().

Post reply on HN