How to Find Duplicate Elements in an Array - Java Program | Java Interview Question and Answer #java

How to Find Duplicate Elements in an Array - Java Program | Java Interview Question and Answer #java

Test Automation Central

1 год назад

119,342 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

cicartaya
cicartaya - 06.09.2023 07:28

I'm just now learning about data structures and algorithms in C++. Correct me if I'm wrong, but I think this approach has a time complexity of O(n^2) because of the nested for loops, which is not that good if the arrays are really large. Is there a better/more efficient way to find duplicates in an array in Java?

Ответить
Omarbek Dinassil
Omarbek Dinassil - 30.08.2023 10:06

I hope you are not a Senior. Because after first interview you will be in a black list😂 P.S. O(n^2) is a awful. You can use Hashset or sort array and find repeatable number

Ответить
Shaik Afrid
Shaik Afrid - 27.08.2023 18:26

It will fail for some edge cases

Ответить
EccomerceBeast
EccomerceBeast - 25.08.2023 10:14

or you can use list
arr.stream().filter(x -> x == 1).toList();

Ответить
NIHANSHU Pethe
NIHANSHU Pethe - 22.08.2023 14:17

Bc 🔥🔥

Ответить
RGB Gaming
RGB Gaming - 22.08.2023 01:53

We can simply use stream for this

Ответить
Jose Joy
Jose Joy - 21.08.2023 19:30

why not just use "for each " element?..

Ответить
Ruben Barkhudaryan
Ruben Barkhudaryan - 13.08.2023 00:30

it doesnt work for 10000 elements arra

Ответить
THD Tech
THD Tech - 19.06.2023 17:54

Good

Ответить
Vikram Prajapati
Vikram Prajapati - 24.05.2023 17:58

Data structure sikh pehle

Ответить
ferozkhan r
ferozkhan r - 23.02.2023 14:30

it wont work if i enter the input like int[] a = {1,4,3,1,4,4};

Ответить