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…
Interviewing programmers: coding test example explained
41–50 of 178 posts
Re: Interviewing programmers: coding test example explained
#42Earlier 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. :-/
Re: Interviewing programmers: coding test example explained
#43Earlier 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…
Re: Interviewing programmers: coding test example explained
#44It 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
#45I'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".
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
#46Earlier 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…
Re: Interviewing programmers: coding test example explained
#47#!/usr/bin/perl
$in = ;
$remove = ;
chomp ($remove);
chomp ($in);
$in =~ s/$remove//g;
Re: Interviewing programmers: coding test example explained
#48Earlier 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.
Re: Interviewing programmers: coding test example explained
#49Re: Interviewing programmers: coding test example explained
#50I'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);}
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().