In the first cracking the coding interview video Ms. McDowell talks about candidates that begin by writing test cases in whiteboard interviews. How would one go about this?
For example, the derivative problem in the video (the candidate is asked to write a function to take derivatives of a list of “Term” structs, which houses two integers, one for coefficients, and one for exponents), would you create a list of Terms, pass it into derivative(), and write the expected solution before even writing the code?
I’m thinking something along the lines of:
derivative([(10,50),(10,0)]) -> [(500,49), (0,0)] derivative([(5,2),(10,1),(5,5)]) -> [(10,1),(10,0),(25,4)]
is this what she means by writing test cases prior to writing code?
Certainly this is how I present test cases in an interview context (though I’m the interviewer in these cases). Doing this ahead of time would be a very positive thing. Identify the likely corner cases, bases cases, etc. and then move on to the design. You could ask the interviewer if they want you to talk more about testing the code before you proceed, but I’d guess they’ll likely say “no” (though personally I think it’s good to ask).