Find lost element from a duplicated array | GeeksforGeeks

preview_player
Показать описание

This video is contributed by Harshit Jain.

Рекомендации по теме
Комментарии
Автор

take sum of two arrays separately as sum1 and sum2 and find difference with Math.abs(sum1-sum2) ..gives the result..

abhijeetjain
Автор

we can solve the same problem using sets in python

def lost_element(arr1, arr2):
A = set(arr1) - set(arr2)
B = set(arr2) - set(arr1)
result = A if len(A)!=0 else B
print(' '.join(map(str, result)))

if __name__=='__main__':
arr1 = list(map(int, input().rstrip().split()))
arr2 = list(map(int, input().rstrip().split()))
lost_element(arr1, arr2)

hritikdj
Автор

another solution is - find out sum of elements individually. lets say s1 is the sum of all the elements in array a1. s2 is the sum of elements in array a2. the missing number is abs(s1-s2)

SuyashSoni
Автор

8:00 why the element at index high will be missing element ...can anyone explain intuition behond it?

akash
Автор

worst explanation common you have read the thing written in explanation ...obviously if someone has come to video must be expecting something extra..basically tell how if mid is equal is both array why are we sure that element will be right of the mid.
Thank you

nishantranjan
Автор

bhai binary search agr lagateh hoh indono array meh toh yeh work nhi kar raha aur agr kar raha h toh explain kro and woh array yeh h arr1[]=[4, 1, 5, 7, 9] and arr2[]=[4, 5, 7, 9] yaha agr mid compute karenge toh 5 ayega toh islogic ke hisab se lost element right hand side hoga jbki woh toh lefthandside h

bipinsingh
Автор

why did we assume that the array is sorted

aviknayak