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

  Рет қаралды 53,429

Naveen AutomationLabs

Naveen AutomationLabs

Күн бұрын

Пікірлер
@ashokanumandla1280
@ashokanumandla1280 3 жыл бұрын
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 colorsSet = new HashSet(); for (int i=0; i
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Yeah correct :)
@shaileshchauhan7043
@shaileshchauhan7043 3 жыл бұрын
@@naveenautomationlabs Superb Video I guess this Ashok Comment is applies for the second way of finding Duplicate element that is with Only hashset. in the Second way as well if there are more then 2 duplicate element then it will keep printing that element. String data[] = {"Amazone","Flipkart", "Myntra", "Amazone","ClubFactory", "Myntra","Amazone"}; HashSet set = new HashSet(); for(String s: data) { if(set.add(s)==false) { System.out.println(s); }; } This will print 2 times Amazone in out put. My question over here is , in interview if they are asking the same question then , which is the best way for finding duplicate element ? i guess HashMap is the correct way .. is my understanding correct ?
@tapaskhandai
@tapaskhandai 2 жыл бұрын
@@shaileshchauhan7043 Yes it is. It will print the element 2nd time if it all total 3 similar element are present and so on.To avoid that we have to add the elements into a Set.
@ankitkatewa2943
@ankitkatewa2943 3 жыл бұрын
U explain things quite well please keep uploading more videos like this
@paladarsh39
@paladarsh39 3 жыл бұрын
Thanks a lot for such awesome videos. This series has helped a lot in preparing for my interviews.
@ramkishore3768
@ramkishore3768 3 жыл бұрын
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.
@christinapo
@christinapo 3 жыл бұрын
Thanks Naveen for the awesome videos. I feel my voice was heard. This would immensely help in prepping for many interviews. Greatly appreciate it. 🙏
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Happy to help:)
@crickettales6594
@crickettales6594 3 жыл бұрын
What a series of questions you are posting🎉🎉
@pradeepvanahalli2279
@pradeepvanahalli2279 3 жыл бұрын
your questions gives a lot of knowledge also increases the interest in java keep motivating us thanks.
@aayushpatel3360
@aayushpatel3360 3 жыл бұрын
mast hai sir aapka ye series. Thank You so much
@rubeenas2004
@rubeenas2004 3 жыл бұрын
You are The Best!!!!!!!!
@Wermax23
@Wermax23 3 жыл бұрын
3. HashMap Map infraMap = new HashMap(); Setduplicates = 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); }
@tannubajpai4782
@tannubajpai4782 3 жыл бұрын
Hello naveen Sir For 2 HashSet Solution Eg:10, 11, 22, 10, 11, 22, 22, 13 ,17 O/P:10,11,22,22
@bhavikapatel7421
@bhavikapatel7421 3 жыл бұрын
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👍
@dp_prajapati
@dp_prajapati 3 жыл бұрын
Thank You Naveen, was looking for something on this...
@wizzard211
@wizzard211 3 жыл бұрын
Fastest and shortest way: String[] strings = {....}; Set set = new HashSet(); Arrays.stream(strings).filter(s -> !set.add(s)).forEach(System.out::println);
@rohitagarwal2601
@rohitagarwal2601 3 жыл бұрын
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
@vinith2320
@vinith2320 3 жыл бұрын
Exactly Rohit... Even I was thinking same
@blue_shadow28
@blue_shadow28 3 жыл бұрын
Inside the interior loop you can use a counter and count the number of entries. If counter is greater than 1 just print the string value and the counter value. Make the counter 0 once u get out of interior loop. Problem solved.
@akshayaamar9825
@akshayaamar9825 3 жыл бұрын
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 map = new HashMap(); for(String element : infra){ if(map.containsKey(name)) System.out.println(element); else map.put(element, 1); }
@sais2218
@sais2218 3 жыл бұрын
Good one Naveen. Keep doing. Also, when you get a chance please do some interviews questions on the custom objects. Thanks.
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Sure I will
@kattasrihari7332
@kattasrihari7332 3 жыл бұрын
Very good content
@phanirajkumarvidiyala8448
@phanirajkumarvidiyala8448 3 жыл бұрын
super good explanation
@pandudamera7211
@pandudamera7211 3 жыл бұрын
Thank you a lot brother
@tajindersingh6519
@tajindersingh6519 3 жыл бұрын
Good one Naveen!!!
@Baigan42
@Baigan42 3 жыл бұрын
Please start series of J2EE with spring Boot, Hibernate and JPA also🙏
@shankarmedhi8074
@shankarmedhi8074 3 жыл бұрын
I also want to print how many time the duplicate element is occuring in the line System.out.println(infra[i]);...could yo u please tell me what to type??
@sudipmitra292
@sudipmitra292 3 жыл бұрын
Really helpful
@anmolmalhi5670
@anmolmalhi5670 3 жыл бұрын
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?
@AsifIquebalSarkar
@AsifIquebalSarkar 3 жыл бұрын
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
@bharathikannanbalakrishnan6514
@bharathikannanbalakrishnan6514 3 жыл бұрын
I thought the same problem. What we can update the solution to make it work?
@Gaurav12081
@Gaurav12081 3 жыл бұрын
hi, Naveen can you make some videos in API automation interview questions using rest assured thanks a lot!
@arushigupta2400
@arushigupta2400 2 жыл бұрын
If we use integar instead of strings then what we need to change in hashmap code?
@prakashbtw678
@prakashbtw678 3 жыл бұрын
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
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
spammers, ignore them.
@tyrepwagyi
@tyrepwagyi 3 жыл бұрын
Thank you so much
@shankarmedhi8074
@shankarmedhi8074 3 жыл бұрын
super helpful
@shankarmedhi8074
@shankarmedhi8074 3 жыл бұрын
HI Naveen, in interivew the interviewer ask me explain with examples for the below terms. I was not able to give statifactory answer. For example; what documenation do. She was looking for defination. It would be greate help to our testing community if you elaborate all the terms. Regards Gaurishankar Maven handles following activities of a developer Build Documentation Reporting Dependencies SCMs Releases Distribution Mailing list
@Poornima_K03
@Poornima_K03 3 жыл бұрын
Thank you
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
You're welcome
@mahatheedandibhotla
@mahatheedandibhotla 3 жыл бұрын
But naveen i request you to cover about streams and then use it directly using streams is a bit confusing and difficult to understand for me
@ketansoni7777
@ketansoni7777 3 жыл бұрын
Set has own property of remove duplicates....
@priyakushwaha9865
@priyakushwaha9865 2 жыл бұрын
How I print out put like if it is coming two times thn print two times Input : [1, 1,4,7,5,3,3] Output :[1, 1,3,3]
@amolmehlawat8197
@amolmehlawat8197 3 жыл бұрын
SOLID principles sir. 😓
Star Pattern Logic - Part 1 - By Naveen AutomationLabs
22:34
Naveen AutomationLabs
Рет қаралды 65 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
IQ 54: Find 2nd highest number in an array list
16:06
The Coding Interview
Рет қаралды 53 М.
ChainTest Report With Selenium + TestNG || Depreciation of ExtentReport
38:48
Naveen AutomationLabs
Рет қаралды 4,8 М.
Tricky Interview Question: Maximum Number of Method Parameters Allowed in #Java
13:31
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН