Find Duplicate Elements in An Array || Important Java Interview Questions

preview_player
Показать описание
In this video, I have explained 6 Ways of Finding Duplicate Elements in An Array.
1. brute force
2. HashSet
3. HashMap
4. Streams

~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:

Follow me on my Facebook Page:

Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:

Naveen AutomationLabs Paid Courses:
Java & Selenium:

Java & API +POSTMAN + RestAssured + HttpClient:
Рекомендации по теме
Комментарии
Автор

Hey Naveen, awesome video... 👍

For other viewers, don't use brute force method if there are more than 2 duplicate entries... it will print the duplicate values multiple times... We can still use, if we keep adding the duplicate item to the HashSet and print the set outside of the loops...

// red color is appearing 3 times in the list
String colors[] = {"red", "blue", "white", "black", "blue", "grey", "red", "pink", "red"};

Set<String> colorsSet = new HashSet<String>();

for (int i=0; i<colors.length; i++) {
for (int j=i+1; j<colors.length; j++) {
if (colors[i].equals(colors[j])) {
colorsSet.add(colors[i]);
}
}
}



Output: [red, blue]

ashokanumandla
Автор

U explain things quite well please keep uploading more videos like this

ankitkatewa
Автор

What a series of questions you are posting🎉🎉

crickettales
Автор

Thank you for your efforts in showing various solutions for the same problem, Speaking of real time why/what is the best solution to be used? Keeping performance, memory and iterations etc. If you can add to your videos would be even much helpful.

ramkishore
Автор

Thanks Naveen for the awesome videos. I feel my voice was heard. This would immensely help in prepping for many interviews. Greatly appreciate it. 🙏

christinapo
Автор

Thanks a lot for such awesome videos. This series has helped a lot in preparing for my interviews.

paladarsh
Автор

your questions gives a lot of knowledge also increases the interest in java keep motivating us thanks.

pradeepvanahalli
Автор

Good one Naveen. Keep doing. Also, when you get a chance please do some interviews questions on the custom objects. Thanks.

sais
Автор

Really helpful. This series is so informative.🙏 If you want to update your self, follow this channel and you can understand any concepts very easily. The explanation is too good.😊Keep it up sir👍

bhavikapatel
Автор

Hello naveen Sir
For 2 HashSet Solution
Eg:10, 11, 22, 10, 11, 22, 22, 13, 17
O/P:10, 11, 22, 22

tannubajpai
Автор

3. HashMap

Map<String, Integer> infraMap = new HashMap<>();
Set<String>duplicates = new HashSet<>();
for (String e:infra) {
if(infraMap.containsKey(e)){
duplicates.add(e);
continue;
}
infraMap.put(e, 1);
}
for (String dups:duplicates
) {
System.out.println(dups);
}

Wermax
Автор

mast hai sir aapka ye series. Thank You so much

aayushpatel
Автор

I find your videos very useful. Thank you for such well explained videos !!! I have provided solution with a single pass in case of HashMap.

HashMap<String, Integer> map = new HashMap<>();
for(String element : infra){
if(map.containsKey(name))
System.out.println(element);
else
map.put(element, 1);
}

akshayaamar
Автор

Please start series of J2EE with spring Boot, Hibernate and JPA also🙏

Tidda
Автор

Using brute force, if Amazon is coming 3 times, it will print Amazon 2 times. And yes the question is to find duplicate elements but we should have something that print the repeatative elements

rohitagarwal
Автор

Thank You Naveen, was looking for something on this...

dp_prajapati
Автор

for the brute force, don't we need to use break in the condition, what will happen if same element is there 3 or more times

AsifIquebalSarkar
Автор

Hello Naveen,
Thanks to your wonderful videos, i got my new job in the market. what you prefer me to learn for mobile browser testing and debugging. I already worked with selenium to use mobile emulator and sauce labs and browser stack. I am not sure about the UI testing for mobile browser testing, do you have any specific video for mobile browser testing?

anmolmalhi
Автор

Hi Naveen, keep rocking.
But see some hackers here mentioned vor today ande gen in in comments. What are they?? Hope they won't spoil your video

prakashbtw
Автор

hi, Naveen can you make some videos in API automation interview questions using rest assured thanks a lot!

Gaurav