Find the missing number, which number is repeated 1 3 2 1 4
Output: repeated and missing number
1 4
Enter the following set of codes:
# program to find the repeating and missing elements
def main():
"""Display repeating and missing elements."""
values = [1, 3, 2, 1, 4]
num_dict = {}
total = len(values)
for i in values:
if i not in num_dict:
num_dict[i] = True
else:
print("Repeated =", i)
for i in range(1, total + 1):
if i not in num_dict:
print("Missing =", i)
main()
Comments
Leave a comment