News for hackers. Stuff that matters.
Re:Bootstrapping My Side Project to $6k/Month by archagon on Thursday November 16, 2017 @02:40PM (#15715821)
That ought to be done in a separate validation step, and/or the tree object should enforce its invariants.

(I shouldn’t be arguing interview problems on HN, but I’ve had a few beers.)

Re:Bootstrapping My Side Project to $6k/Month by vkou on Thursday November 16, 2017 @05:34PM (#15717323)
I argue that if an interview question asks you to implement parseInt(String foo), it's your responsibility to handle inputs that aren't a properly formatted integer gracefully.

Or at least to point out to the interviewer that your solution fails to handle unexpected input, and ask if they want you to add input validation logic, or if they are satisfied with the answer.

Re:Bootstrapping My Side Project to $6k/Month by archagon on Thursday November 16, 2017 @05:46PM (#15717399)
Sure, but this assumes that foo is a valid String — just formatted incorrectly for use with an int. If we can't assume that TreeNode constitutes a valid (cycle-free) tree, we essentially have to embed a full cycle-checker in our otherwise simple inversion function. I would argue that goes against the intent of the question.