Live data from Hacker News

Interviewing programmers: coding test example explained

solipsys.co.uk

21–30 of 178 posts

Re: Interviewing programmers: coding test example explained

#21

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".

Re: Interviewing programmers: coding test example explained

#22
post #8

Am I OCD when I cringe when I see 'p_rite' where he (I think) means 'p_write'? That alone would knock a few points off a candidate doing this test when he's interviewing with me. 'rite' can mean 'write' or 'right' or even 'allright' - why the unnecessary confusion?

I think he used p_rite so that the variable names length is identical to p_read, which can make the code look more pretty.

I like having the variables the same length from an aesthetic point, but my brain also flags 'rite' as being spelled wrong and that detracts (albeit slightly) from reading and understanding the code.

Re: Interviewing programmers: coding test example explained

#23
post #10
post #8

Am I OCD when I cringe when I see 'p_rite' where he (I think) means 'p_write'? That alone would knock a few points off a candidate doing this test when he's interviewing with me. 'rite' can mean 'write' or 'right' or even 'allright' - why the unnecessary confusion?

You're not alone in feeling the OCD twinge, but are almost certainly alone in being willing to demerit a candidate writing that.

Actually, he's not alone in demeriting =)

Re: Interviewing programmers: coding test example explained

#24
post #7

1) In TFA, s/cersion/version/, but that's an amusing typo. :-) 2) Initializing inside the for loop requires C99; is that to be considered idiomatic? I didn't think so. I'll be curious how many submissions were either identical to your suggested idiomatic solution or its K&R equiv: https://gist.github.com/3f4daf24595788258a01 :-)

Although I'm not sure "its K&R equivalent" is correct (that's C89 and has "modern" function implementations), C99 is indeed not that common. If only because many compilers don't support it (including Microsoft's).

Re: Interviewing programmers: coding test example explained

#25
post #8

Am I OCD when I cringe when I see 'p_rite' where he (I think) means 'p_write'? That alone would knock a few points off a candidate doing this test when he's interviewing with me. 'rite' can mean 'write' or 'right' or even 'allright' - why the unnecessary confusion?

I think he used p_rite so that the variable names length is identical to p_read, which can make the code look more pretty.

Yes that's what I figured, but still that's only in one place (in the declaration).

Re: Interviewing programmers: coding test example explained

#26
post #10
post #8

Am I OCD when I cringe when I see 'p_rite' where he (I think) means 'p_write'? That alone would knock a few points off a candidate doing this test when he's interviewing with me. 'rite' can mean 'write' or 'right' or even 'allright' - why the unnecessary confusion?

You're not alone in feeling the OCD twinge, but are almost certainly alone in being willing to demerit a candidate writing that.

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

Re: Interviewing programmers: coding test example explained

#28

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.

Usually "inplace" means "in constant memory space." In other words, running the algorithm on an input of size N requires the same amount of memory as running the algorithm on an input of size M.

Re: Interviewing programmers: coding test example explained

#29
post #7

1) In TFA, s/cersion/version/, but that's an amusing typo. :-) 2) Initializing inside the for loop requires C99; is that to be considered idiomatic? I didn't think so. I'll be curious how many submissions were either identical to your suggested idiomatic solution or its K&R equiv: https://gist.github.com/3f4daf24595788258a01 :-)

Although I'm not sure "its K&R equivalent" is correct (that's C89 and has "modern" function implementations), C99 is indeed not that common. If only because many compilers don't support it (including Microsoft's).

Bah, I learned my C from K&R 2nd ed. I guess that's not K&R C, is it? :-)

Re: Interviewing programmers: coding test example explained

#30
post #9

Earlier quoted context omitted.

Yeah, I had almost exactly the same code. I'm sure most people did too. The only other "obvious" algorithm is the n^2 one.

You will be surprised.

I like surprises! Looking forward to part 3...
Post reply on HN