Hacker News new | ask | show | jobs
by Double_a_92 2770 days ago
Would you be looking for the solution where you subtract every number in the array from 5050? If anyone says that they 99% studied it.

A more "natural" sulution would be to sort the list first, and then look for consecutive array items where the difference is not 1.

4 comments

I just woke up (still in bed). I've not seen this question before. For about 2 seconds I thought of iterating through and creating a map and... Wait a second, if one number is missing, I can just find the sum and subtract! Admittedly, I would have had much more trouble in a high pressure situation.

I think questions like this are fun and novel and also have absolutely no place in an interview for software developers.

Edit: the slightest of arguments for a question like this is can they find novel runtime optimizations. A work sample test is better. Grab some crap code from the codebase like a double forloop that should have been a map look up and have them make it more performant.

Would you be looking for the solution where you subtract every number in the array from 5050?

Unless they can swear up and down that what they actually do at this company, for at least a significant part of the day, is throw each other against the wall (er umm, whiteboard) and insist that they solve problems like these (and do so elegantly) within 10 minutes or less...

... or get fired ...

... then what I'll be looking for is simply -- the door.

Would you be looking for the solution where you subtract every number in the array from 5050? If anyone says that they 99% studied it.

I was asked this exact question at my on-campus interview with one of the Big Five software companies for a Program Manager internshi between my 3rd and 4th years of college.

I had done no “leetcode grinding”-style prep.

Subtract from 5050? No, I didn’t think of that. But I did think of summing the numbers 1..100 with a for loop, sum the numbers in the input array, and subtract.

Not the perfect solution. But it’s O(n).

And I did get the internship.

My point being not that I’m some kind of algorithmic prodigy: I’m very much not. But if a college kid can solve it without any prep, nor rote memorization as GP suggests...

If you're asked to sort a list and if you suggest something better than bubble sort, it means you 100% studied it. There is no way someone could come up with the quicksort(or alike) algorithm on an interview.
Insertion sort is actually the one that comes naturally for me. :)