Hacker News new | ask | show | jobs
by jkarneges 3752 days ago
This happened to a friend. He confirmed that pseudocode would be acceptable, but then as he was writing it out the interviewer got on him about not terminating lines with semicolons (I suppose the pseudocode looked C-ish). So yeah I'd say make this clear.
3 comments

Ack. I'm not sure how I'd react to that.

I interviewed quite a bit last year (on the hiring side). I was really surprised by the variation in pseudocode written by the candidates. Most wrote something JavaScript-like, a few stuck to mostly proper Java or C. But then one dumped a giant web of crazy on the board (but still made his point) and one wrote something that looked suspiciously like COBOL - still not sure if he was trolling me.

"and one wrote something that looked suspiciously like COBOL - still not sure if he was trolling me."

That's brilliant. Now I have to learn myself some COBOL just for that.

You will need to write a lot before you even start solving the problem.
My pseudocode used to be a sort of relaxed Haskell, because it's closer to how I think about a solution... but some interviewers rejected it as not resembling any kind of code, so now I use something imperative and Pythonesque, which hasn't gotten complaints so far. The sad thing was that in some cases the Haskell "pseudocode", unlike the Python, would have actually compiled and solved the problem quickly (within a factor of ~4 of C), and it took me about a minute to write.

Unfortunately I think Haskell is disproportionately well-suited to these kind of toy problems, so being able to answer interview questions in Haskell doesn't tell the interviewers much except that you think yourself especially clever.

> Ack. I'm not sure how I'd react to that.

Thank them for their time, leave, move on to next company.

I always write a weird mashup between python and C for some reason haha
I wrote some Ruby in an interview. It was so terse, I had to explain to the interviewer (who favored Java) what the code did, and why it was linear instead of O(n^2). That was actually kind of fun.
If your code is sufficiently terse that it's not very understandable (such that the complexity isn't very understandable) surely that's a realistic red flag?
If it's idiomatic Ruby (which some, like me, are not familiar with), I think it would not be a red flag if they could explain the details of what the syntactic sugar represents, and why its runtime is what it is.
My shipping boxes hold an even number of widgets, but I "have to" sell odd quantities and those need expensive mil spec styrofoam peanuts added to fill the hole. Here, have an array of possible shipment sizes. Given that array, if its shipping an odd number of widgets I wanna add an additional half widget shipping charge.

newshipping = oldshipping.select{|i| i % 2 == 1 }.map{|i| i + 0.5 }

My ridiculous fictional writing about shipping widgets is way more confusing than the idea that you can select and then chain right into a map.

This probably looks really weird to a java guy but its not really all that mysterious. I wonder what that looks like in Java.

In Java it would look like this:

List<Double> newshipping = oldshipping.stream().filter(i -> i % 2 == 1).map(i -> i + 0.5d).collect(Collectors.toList());

a bit more verbose but the essential chaining idea is there...

The above, only if you want to discard (filter) orders with an even number of things.

Also I'm not sure about the use of floating point here...

"Shame! You're not terminating your pseudo-code with semicolons!!!"

I'd respond to that by drawing one huge semi-colon that spanned all 20 lines of pseudo-code.