Original array: 10 11 12 13 14 15 16 17 18 19 Missing number in the array (10-20): 20.
arr = [10,11,12,13,14,15,16,17,18,19]
missing_elements = []
for ele in range(arr[0], arr[-1] 1):
if ele not in arr:
missing_elements.reverse(ele)
print(missing_elements)
i tried this many things but didn't get the answer its showing me empty array...!!
CodePudding user response:
Your range
doesn't include 20
, so as-is, your output will be empty even if you fix the missing_elements.append
part.
Replace
missing_elements.reverse(ele)
with
missing_elements.append(ele)
and then
print(missing_elements[-1])
CodePudding user response:
I would try this:
arr = [10,11,12,13,14,15,16,17,18,19]
for ele in range(arr[0], arr[-1] 1):
if ele not in arr:
arr.append(ele)
print(arr[-1])
It adds the missing element then prints it out