-3

This question already has an answer here:

I'm in for my first programming interview ever having done a Ph.D. in CS and previously only worked in academic positions. Therefore, I have a question about interviews at places like Google etc. I've put down on my resume that I know C, C++ and various functional programming languages very well. I was planning on writing my code during the interview in C unless I'm specifically asked to use another language.

The only problem with using C is that there is no built in implementation of a hash function. Many interview questions I've seen online often require hashing. Is it OK in these interviews to assume the existence of a hash function in these cases? Or am I expected to write a hash function for whatever struct I'm defining? In other words, do they expect my C code to always be a complete program that one can run?

marked as duplicate by gnat, Jan Doggen, Jim G., Chris E, user8365 Dec 12 '14 at 14:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    It depends on the interview and the interviewer and how much time they want to allocate to you to write your hash function. Ask your interviewers and go by what they tell you. – Vietnhi Phuvan Dec 12 '14 at 9:39
  • 3
    This question appears very specific to programming/software development, and I don't really see how to edit it for "general workplace-relatedness" without completely eviscerating it. See here. Should this be migrated to programmers.SE? – Stephan Kolassa Dec 12 '14 at 9:47
  • @StephanKolassa unlikely that migration would be welcome – gnat Dec 12 '14 at 10:02
  • OK, based on the comments, I'll just implement Jenkin's hash function during the interview as it can be written down as a very short skeleton (just showing I know how to implement a hash that is type agnostic) and leave the constants in there as question marks telling them that I would look it up, if I would ever need them... It takes 30s to do this and I can ask them if it's needed while doing it... this shows I know how and at the same time will ask. – dst Dec 12 '14 at 10:18
  • This could be generalized to any technical or hands on skill where you're demonstrating in one medium (pencil sketching), but will be working in another (digital or water colors). – user8365 Dec 12 '14 at 14:05
2

Will you likely need to implement your own hash function on the actual job? I'd guess not. This particular wheel has been invented many, many times. There are libraries for this kind of thing.

So, assuming that the interview is supposed to test your knowledge of stuff you actually need for the position you are interviewing for, I would guess that you can assume the existence of a hash function.

Nevertheless, as @Vietnhi notes, you should of course ask during the interview. Just as you should ask a lot of questions to clarify what you are supposed to be doing, and what you can assume. This kind of back-and-forth to clarify requirements is integral to any programming job.

EDIT: this is enlightening. (Link via Kate Gregory's comment here.)

  • 1
    If I were an interviewer, I'd take a candidate's failure to scope out a task before executing it as a bad sign. – Vietnhi Phuvan Dec 12 '14 at 9:47
  • KateGregory's answer is absolutely great. We have had a few questions about whiteboards recently and her answer needs to be referred to. – Vietnhi Phuvan Dec 12 '14 at 10:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.