def printElement(arr, size):
for i in range(size):
if arr[abs(arr[i]) - 1] > 0:
arr[abs(arr[i]) - 1] = -arr[abs(arr[i]) - 1]
else:
print("The repeating element is", abs(arr[i]))
for i in range(size):
if arr[i] > 0:
print("and the missing element is", i + 1)
arr = [2, 3, 4, 4, 6, 7, 8]
n = len(arr)
printElement(arr, n)
Question:
Find the repeating and the missing element in an List
Explanation:
We need to find any repeating element and missing element in a given unsorted elements in a list.
For Example:
List [2, 3, 4, 4, 6, 7, 8]
Result:
The repeating element is 4 and missing element is 5
Program:
---------End---------