A more "natural" sulution would be to sort the list first, and then look for consecutive array items where the difference is not 1.
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.
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.
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...
How do you find the missing number in a given integer array of 1 to 100? (solution) [1]
How do you land a job at "startups like Uber and Netflix; big organizations like Amazon, Microsoft, and Google; and service-based companies like Infosys or Luxsoft"?
Easy - by rote memorization. And a healthy sense that it's to best not question the basic idiocy behind cargo-cult interview tactics like these.
Because apparently genuinely useful critical thinking skills -- beyond such trivial matters such as how to get a better space-time tradeoff on that petabyte-scale fibanocci generator[2] our customer desperately needs you to design a viable POC for right now, on the whiteboard, before lunch -- basically aren't needed at these companies.
Notes:
[1] You think I'm just being snarky? It's famously common out in hedgefund-land for people to get hired more or less on the basis of being able to whip out a deadpan response to "gee-whiz" questions like these. And to get "flushed" for their inability to do the same. Startups aren't quite so naively reliant on shibboleth questions of this sort -- but but only slightly so.
[2] I'm being slightly hyperbolic with this example -- but only slightly. I've long since lost count of the number of times been asked "design" questions really only slightly more ridiculous than this example. And as a matter of fact I've been asked an "advanced fibanocci" question -- and apparently received a job offer to a large extent on the basis of my ability to "nail" it -- quite recently