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

  Рет қаралды 126,386

Test Automation Central

Test Automation Central

Жыл бұрын

How to Find Duplicate Elements in an Array - Java Program | Java Interview Question and Answer | Test Automation Central
For source code, visit - testautomationcentral.com/how...
Automation Testing Interview Question | Selenium WebDriver Java Interview Question | Automation Tutorials | Selenium Tutorials | Testing Automation Tutorials | Test Automation | Java Selenium | Automation Interview Question And Answers | ChromeDriver Class | WebDriver Interface
#sdet #seleniumtutorial #automationtester #automationtesting #javaprogramming #javatutorial #javaprogram #javaquestions #testautomation #testautomationcentral #seleniumtutorialforbeginners #seleniumwebdriver #javaselenium #seleniuminterview #finaljava
#seleniumforbeginners #sdetinterview #seleniumquestions #chromedriver #webdriver #webdriverinterface #seleniumwebdriver #windowhandles #javaprogram #javaprogramming #javaarrays

Пікірлер: 34
@TestAutomationCentral
@TestAutomationCentral Жыл бұрын
For detailed tutorials and source code, visit - testautomationcentral.com/how-to-find-duplicate-elements-in-an-array-java-program-java-interview-question-and-answer/
@akaki_khotcholava
@akaki_khotcholava 7 ай бұрын
Time complexity is O(n**2). You can easily use HasMap and one for loop. I can provide JS code. And time complexity for this code will be O(n) function findDuplicates(arr) { const elementCount = {}; const duplicates = []; arr.forEach((element) => { // Initialize count for the element or increment existing count elementCount[element] = (elementCount[element] || 0) + 1; // Check if the element is a duplicate and hasn't been added to duplicates array yet if (elementCount[element] === 2) { duplicates.push(element); } }); return duplicates; }
@JohnWickea
@JohnWickea 4 ай бұрын
lol your code is worse . check your space complexity xD. I can solve all this in O(n) lol.
@akaki_khotcholava
@akaki_khotcholava 4 ай бұрын
@@JohnWickea You must be a genius.
@ladro_magro5737
@ladro_magro5737 3 ай бұрын
taking extra space is also not a good solution there is a much better way to handle this case with no extra space and O(n) time complexity
@JohnWickea
@JohnWickea 3 ай бұрын
@@ladro_magro5737 let the kimd live in it's own universe, since he's not listening to anyone 😂
@ahmedshaltout4437
@ahmedshaltout4437 Ай бұрын
any operation on hashmap cost O(log N) time
@ViktorTheRook
@ViktorTheRook 4 ай бұрын
U can sort array, iterate array and check array index i and i +1 until end of array… constant space and O(nlogn) because of sort…. Or use hash map for linear time but also linear space
@cicartaya
@cicartaya 11 ай бұрын
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?
@sergeiivanov5739
@sergeiivanov5739 10 ай бұрын
Sets...
@electricity2703
@electricity2703 7 ай бұрын
It takes combination(array.size(), 2) iteration
@arsalanalam9622
@arsalanalam9622 3 ай бұрын
It doesn't work when you have multiple duplicate elements in same array
@vedantjoshi2093
@vedantjoshi2093 26 күн бұрын
No need for two for loops..it can be done in one
@anubhav.codess
@anubhav.codess 8 ай бұрын
Using hashmap and print the elements whose frequency is greater than 1 easy pezzy
@theanimemanofindia8036
@theanimemanofindia8036 7 ай бұрын
Bro it is for the people who are only say core Java experience not collection
@Pearl0812
@Pearl0812 9 күн бұрын
How to remove that??
@crosswalker45
@crosswalker45 5 ай бұрын
Instead of brute force, try to implement other approach like hsshmap.
@mySofCh786
@mySofCh786 6 ай бұрын
Don't use 2 for loop, don't use set/hashset
@rgbgaming11
@rgbgaming11 11 ай бұрын
We can simply use stream for this
@prady1006
@prady1006 11 ай бұрын
In interview they will tell u stream is doing fine. Create your logic then you have to learn basic bro
@jasonosunkoya
@jasonosunkoya 3 ай бұрын
Just use a hashmap,
@nikhilraj1812
@nikhilraj1812 Ай бұрын
Hey bro can we use two pointer for this question?👀
@josejoy174
@josejoy174 11 ай бұрын
why not just use "for each " element?..
@eccomercebeast8911
@eccomercebeast8911 11 ай бұрын
or you can use list arr.stream().filter(x -> x == 1).toList();
@ChatGPT......
@ChatGPT...... 9 ай бұрын
😢wah bhi
@akashsarjine
@akashsarjine 5 ай бұрын
Use distinct
@rubenbarkhudaryan5606
@rubenbarkhudaryan5606 11 ай бұрын
it doesnt work for 10000 elements arra
@Thd369
@Thd369 Жыл бұрын
Good
@dekhlohhgftgdrf6038
@dekhlohhgftgdrf6038 2 ай бұрын
What if all numbers were same let's say 1
@Omkar_manjare
@Omkar_manjare 2 ай бұрын
Not optimized solution
@nihanshupethe8983
@nihanshupethe8983 11 ай бұрын
Bc 🔥🔥
@shaikafrid2186
@shaikafrid2186 11 ай бұрын
It will fail for some edge cases
@subhojitbiswas3876
@subhojitbiswas3876 10 ай бұрын
Ye s like if in the last if u have one more 1
@bikramprajapati5358
@bikramprajapati5358 Жыл бұрын
Data structure sikh pehle
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 4,6 МЛН
Best KFC Homemade For My Son #cooking #shorts
00:58
BANKII
Рет қаралды 69 МЛН
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 28 МЛН
Java Mock Interview | Fresher Java Technical Round | OOP Concept | Core Java Interview Questions
22:44
How to Find Duplicate Words in a String in Java | Coding Skills
24:36
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 255 М.
Remove Duplicates from sorted Array
21:22
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 168 М.
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 509 М.
哈哈这些娃娃可烦人了!#火影忍者 #佐助 #家庭
0:31
火影忍者一家
Рет қаралды 34 МЛН
Я обещал подарить ему самокат!
1:00
Vlad Samokatchik
Рет қаралды 9 МЛН
Don´t WASTE FOOD pt.4 🍜
0:20
LosWagners ENG
Рет қаралды 6 МЛН
Мужик купил китайское авто и сразу поехал в СЕРВИС
0:14
Собиратель новостей
Рет қаралды 4,2 МЛН
Draw your favorite | Inside Out Graffitis
0:30
AmogusMan
Рет қаралды 14 МЛН