
Missing order number
easyMissing order number
Walmart Python Interview Question
Walmart's warehouse system numbers the packages in a shipment from 0 to n, so a shipment has n + 1 packages. One package went missing on the way, so only n packages arrived.
Write a function missing_number(numbers) that takes the n package numbers that arrived, in any order, and returns the one number from 0 to n that is missing.
Asked of
- Data Analyst
- Data Engineer
- Data Scientist
- ML Engineer
- AI Engineer
Example 1
Input
numbers = [3, 0, 1]
Output
2
Example 2
Input
numbers = [0, 1]
Output
2
Explanation
In the first example, 3 numbers arrived, so n is 3 and the shipment held 4 packages, numbered 0 to 3. Package 2 is the only one not in the list. In the second example, 0 and 1 arrived, so n is 2 and the shipment held packages 0, 1 and 2. Package 2, the last one, is missing.
Submit also runs 3 hidden test cases that check edge cases.
Company
Walmart
Difficulty
easy
Topic
math
Language
Python
Your code
Loading Python in the background. You can start writing.