Edit: This answer assumes the set of 41 has to include the original set of 40.
You really have two problems:
Finding a 41st Number
What you're looking for here is a gap where you can sneak in a new number, so the first thing you'll need to do is sort it.
With your sorted list in hand, the easy shortcuts are to see if there's a gap at the beginning (first number is greater than 1) or the end (last number is less than 1,000). If either of those is true, the 41st item can be 1 or a 1,000 depending on which it is. You're done.
If the sorted list contains 1 and 1,000, you have to traverse it until you find two adjacent numbers that have a difference greater than one. The space between those two numbers represent the gap, and the 41st item is some number in that gap. The easiest thing to do would be one greater than the lesser of the two numbers of one less than the greater.
Restoring the Original 40 Numbers
Your friend's problem has a flaw in that it doesn't provide any information about how the original set of 40 numbers are provided (unordered set, list, etc.) or how the set containing the 41st number should be returned.
If the sets provided and returned are actually a 40-item ordered (just ordered, not necessarily sorted) list, the new number can be appended as the 41st item and then lopped off later to get back to the original.
If the sets are unordered, there's no way to figure out which item has to be removed to restore the original 40. You just don't know what was added.
You might think there's some clever way of giving the number you add some intelligence that will reveal the identity of the added number when you're handed a set of 41 later, but there isn't. Someone who knows your algorithm could construct a valid set of 40 that will result in a set of 41 that yields the wrong answer when cut back to 40.