Find Duplicate element in an array || 2 methods

preview_player
Показать описание
This video shows 2 processes to find duplicate element in any type of array. First method is shown using SET data structure and second process by simply negating elements of an array.
PLEASE help us reach 1K subscriber by hitting the SUBSCRIBE button below. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
Рекомендации по теме
Комментарии
Автор

Not working sec code and also not clearly explained..

CallMeKRSNA
Автор

ERROR IN 2ND APPROACH.
abs( A(i)) is always >=0.
So it should be A[ abs(a[i])].

jalsacentre
Автор

what if 0 is present in array, negative of 0 is zero

shouryasingh
Автор

2nd approach not understood everytime it is checking absolute calue so each iteration if statement will work, can u explain it again with correction

SomnathDas-fgqc
Автор

1st method mein agr input mein hm ek hi element ko baar baar daal di en... To ue baar baar print krata rhega..
Ex- 1, 2, 2, 1, 1
Ouput will be- 2, 1, 1

nadraibrahim
Автор

Tech dose I have a doubt in the second approach, you are checking the absolute value of each number, when you checking element at index 3, the value is -3, then abs(-3) is 3 and 3 is greater than 0 man then how it will move to else block and how it will print the duplicate number??? Are you crazy?? I did the code for this algorithm but it's not printing any result. If I wrong send the code or if you wrong then explain🙁

sakthim
Автор

The problem comes with an assumption that values inside the array will be in the range [0, size-1]. So the idea is as follows. Whenever we traverse an element with value i, we make the ith indexed element as negative. So whenever we come across a duplicate element with ths same i value and try to make the ith indexed element as negative, it is already negative. Hence we arrived at the duplicate element. The absolute check is for when a current element is already negated by another element in order to avoid IndexOutOfBoundException. Sounds good!!

askchaitanya
Автор

What is there is a 100 in the array input? Like - [100, 1, 3, 2, 3, 5]

nithinbosej
Автор

Insertion and searching in set will take log(n) time, so the time complexity will be n*log(n).Am I right?

SunitaSharma-bipm
Автор

First method doesn't work if element is repeated more that 2 time, it gives duplicate output

haseen
Автор

Correct code link is given in description u can chk frm there.👍

CallMeKRSNA
Автор

Awesome video 😊.
Plz give the 1st code also 🙏

arkoprovo
Автор

How negative elements greater than 0 not working

nagarajupandaga
Автор

Asked in my interview no idea😭😭😭now understood

RTX_valorant
Автор

Even this approach is good because you are checking based on indexes values


if the array size is 4 and it contains value like arr[11, 15, 22, 15] then it won't work man

sunnymaurya
Автор

This is very unprofessional. Second method not explained properly youtuber was in hurray

akashmore
Автор

you should remove this vedio its not correct

faizanowaishvlogs