Top MNC interview question which will be very useful for beginners to crack the interview and for there future careers

test

Breaking

Post Top Ad

Your Ad Spot

Sunday, December 27, 2020

Microsoft Interview Question(Find the repeating and the missing element in an list)

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:

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
)

                                                                ---------End---------

Post Top Ad

Your Ad Spot