News for hackers. Stuff that matters.
Re:What do the best interviewers have in common? by 0xfeba on Thursday November 30, 2017 @08:26PM (#15821235)
> A simple one I have asked in C is to reverse the order of numbers in an array in place.

Hm...

    int a[] = {1,2,3,4,5};
So, some kind of swap?

    for (x = 0, y = 4; x < 5; x++, y--) {
      a[x] ^= a[y]; a[y] ^= a[x]; a[x] ^= a[y];
    }
See, I wouldn't mind that on a whiteboard. I had similar question for a startup, and passed easily (I think!).

But then the last question I got was 'find all word substrings in a string'. I struggled, giving a brute force answer (for each position in the string, check against dictionary and expand by one character until the end of the string), but struggled to improve on it. I didn't know about tries at the time, but even still it would be difficult for me to even try to code this on a whiteboard. Turns out it was "Google" question that was for optimizing runtime, and I cannot analyze like that on a whiteboard, unless it's obvious (nested for loops, etc.).

Anyway, after struggling and giving up with that question the next guy came in and berated me and my current employer (defense contractor). Not sure if it was because they thought I wasted their time or what. I left after that--not someone I would want to work for.

Re:What do the best interviewers have in common? by pkaye on Thursday November 30, 2017 @11:01PM (#15821811)
Should have mentioned that temporaries are allowed. Also you swapped the array elements twice... The terminating condition should be x == y.

Also if you changed this to a int *a (and a count), some people will get confused how to do this all with pointers. Asking how this would be tested is also a good question.

Re:What do the best interviewers have in common? by jaredsohn on Thursday November 30, 2017 @11:56PM (#15822028)
>The terminating condition should be x == y

That assumes an odd number of elements (true in this case but not in general); I would recommend terminating when x >= y.

Re:What do the best interviewers have in common? by 0xfeba on Friday December 01, 2017 @11:51AM (#15825083)
ah, whoops!
Re:What do the best interviewers have in common? by allenlavoie on Thursday November 30, 2017 @10:42PM (#15821739)
It's a nice xor swap, but I think you reversed your list twice. And xor swapping with x=y=2 is likely not ideal. Seems like exactly what I'd do in an interview too :p
Re:What do the best interviewers have in common? by CodesInChaos on Friday December 01, 2017 @04:33AM (#15822870)
The xor swap failure when working on the same variable has been nicely exploited in the underhanded C contest: http://www.underhanded-c.org/_page_id_16.html

> The XOR-swap trick is an example of coders being too clever for their own good. Here, it gradually poisons the RC4 permutation with zeroes, until eventually the plaintext is just passed along in the clear.

Re:What do the best interviewers have in common? by 0xfeba on Friday December 01, 2017 @01:35PM (#15826054)
Ha! Those are always good reads. Thanks.
Re:What do the best interviewers have in common? by 0xfeba on Friday December 01, 2017 @11:51AM (#15825093)
See, I'd need to run and debug it to figure all that out.

But apparently some people can just write it all out on a whiteboard in one go.