Find All Duplicates in an Array | LeetCode 442 | C++, Java, Python

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

**** Best Books For Data Structures & Algorithms for Interviews:**********
*****************************************************************************

August LeetCoding Challenge | Problem 6 | Find All Duplicates in an Array | 6 August,
Facebook Coding Interview question,
google coding interview question,
leetcode,
Find All Duplicates in an Array,
Find All Duplicates in an Array c++,
Find All Duplicates in an Array Java,
Find All Duplicates in an Array python,
Find All Duplicates in an Array solution,
442. Find All Duplicates in an Array,

#CodingInterview #LeetCode #AugustCodingChallenge #Google #Amazon #Duplicates
Рекомендации по теме
Комментарии
Автор

ur background is really intelligently selected as it stops the reflection..& explaination was great..

mandeep
Автор

why we took abs of n .
n is index and we are making the no. at n negative.

himanshupatel
Автор

Thanks for your effort. I do understand the technique used, but I don't understand why it works??

Ahmedmeshref
Автор

Nice Approach, sir
Thanks for sharing.

risavkumarjha
Автор

sir but this approach at 5:27 won't work when we have nos. repeating thrice

tulikachhaukhhadiya
Автор

Just xoring all the elemnts in order to extract the unique elements & store them & them later on xoring this resultant unique elements with the whole array so that we left with only duplicate elements & store & then return them into an array...

GR_EDITZZZ
Автор

Very Good technique Sir, Nicely Explained

mainakbanerjee
Автор

Isn't it should be nums[nums[n-1]]*=-1.
Please someone help me.Thanks

hrithikrudra
Автор

What if the array elements are {12, 13, ...} Like this.. how can we go to the 12th 13th index. Will this solution work for this?

hereweare
Автор

When you flip sign you use one bit in the input data, so it's still O(N) space solution.

andreykalmatskiy
Автор

what if we are not allowed to modify the original array?

subhambanerjee
Автор

They have specified that we cannot use exrta space. But result array is extra space right? Please correct me if I'm wrong here

PiBiNi
Автор

Can we do sorting first and then check if arr[i]!= arr[i-1] ?

kajalpareek
Автор

Here's how Im gonna do it:-

ar = [4, 3, 2, 7, 8, 2, 3, 1]

count = []

for i in range(len(ar)):
if ar[i] not in count:
count.append(ar[i])
else:
print(ar[i], 'is occuring more than once')

akshitkushwaha
Автор

But u modified the array
And in Ques there is given that you cannot modified the array

akashgupta
Автор

What tools are you using ?? Black board and Software to write using pen tablet.

SangelRally
Автор

Not satisfied with the answer. Came here in search of a simple solution that works for any array but found a complex solution.
Can we do it without using a vector or list, with the simple array?
What if we have {102, 203, -405, 203, 43, 78, 102, 202}. How we will find the duplicate only using simple array concept?

rajeevranjan-tuyv
Автор

This is not working with the following input ->
int[] numRay = {17, 27, 11, 23, 14, 29, 17, 24, 3, 6, 18, 8, 18, 16, 29, 11, 24, 5, 0, 1, 28, 3, 28, 4, 13, 7, 7, 27, 10, 21};

Expected solution-> [3, 7, 11, 17, 18, 24, 27, 28, 29]
Actual solution -> [3, 7, 11, 17, 24, 27, 28, 29]


My solution (instead of multiply, using addition)
int[] numRay = {17, 27, 11, 23, 14, 29, 17, 24, 3, 6, 18, 8, 18, 16, 29, 11, 24, 5, 0, 1, 28, 3, 28, 4, 13, 7, 7, 27, 10, 21};
int constant = numRay.length;
Set<Integer> solution = new TreeSet<>();
for (int n : numRay) {
if (n >= constant) {
n = n - constant;
}
if (numRay[n] < constant) {
numRay[n] = numRay[n] + constant;
} else {
solution.add(n);
}
}

DhananjaySharma-kbyf
Автор

Bhai, naya question ka solution ? Vertical order B Tree. Would like to learn from your example

TheMsnitish
Автор

Sir this solution was so cool and simplified. I thought of using rabbit and tortoise so went in a wrong direction.

One request: please do explanation and code to check Bipartite.

jay-rathod-