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
@naveenautomationlabs3 жыл бұрын
Yeah correct :)
@shaileshchauhan70433 жыл бұрын
@@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 ?
@tapaskhandai2 жыл бұрын
@@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.
@ankitkatewa29433 жыл бұрын
U explain things quite well please keep uploading more videos like this
@paladarsh393 жыл бұрын
Thanks a lot for such awesome videos. This series has helped a lot in preparing for my interviews.
@ramkishore37683 жыл бұрын
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.
@christinapo3 жыл бұрын
Thanks Naveen for the awesome videos. I feel my voice was heard. This would immensely help in prepping for many interviews. Greatly appreciate it. 🙏
@naveenautomationlabs3 жыл бұрын
Happy to help:)
@crickettales65943 жыл бұрын
What a series of questions you are posting🎉🎉
@pradeepvanahalli22793 жыл бұрын
your questions gives a lot of knowledge also increases the interest in java keep motivating us thanks.
@aayushpatel33603 жыл бұрын
mast hai sir aapka ye series. Thank You so much
@rubeenas20043 жыл бұрын
You are The Best!!!!!!!!
@Wermax233 жыл бұрын
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); }
@tannubajpai47823 жыл бұрын
Hello naveen Sir For 2 HashSet Solution Eg:10, 11, 22, 10, 11, 22, 22, 13 ,17 O/P:10,11,22,22
@bhavikapatel74213 жыл бұрын
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_prajapati3 жыл бұрын
Thank You Naveen, was looking for something on this...
@wizzard2113 жыл бұрын
Fastest and shortest way: String[] strings = {....}; Set set = new HashSet(); Arrays.stream(strings).filter(s -> !set.add(s)).forEach(System.out::println);
@rohitagarwal26013 жыл бұрын
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
@vinith23203 жыл бұрын
Exactly Rohit... Even I was thinking same
@blue_shadow283 жыл бұрын
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.
@akshayaamar98253 жыл бұрын
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); }
@sais22183 жыл бұрын
Good one Naveen. Keep doing. Also, when you get a chance please do some interviews questions on the custom objects. Thanks.
@naveenautomationlabs3 жыл бұрын
Sure I will
@kattasrihari73323 жыл бұрын
Very good content
@phanirajkumarvidiyala84483 жыл бұрын
super good explanation
@pandudamera72113 жыл бұрын
Thank you a lot brother
@tajindersingh65193 жыл бұрын
Good one Naveen!!!
@Baigan423 жыл бұрын
Please start series of J2EE with spring Boot, Hibernate and JPA also🙏
@shankarmedhi80743 жыл бұрын
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??
@sudipmitra2923 жыл бұрын
Really helpful
@anmolmalhi56703 жыл бұрын
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?
@AsifIquebalSarkar3 жыл бұрын
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
@bharathikannanbalakrishnan65143 жыл бұрын
I thought the same problem. What we can update the solution to make it work?
@Gaurav120813 жыл бұрын
hi, Naveen can you make some videos in API automation interview questions using rest assured thanks a lot!
@arushigupta24002 жыл бұрын
If we use integar instead of strings then what we need to change in hashmap code?
@prakashbtw6783 жыл бұрын
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
@naveenautomationlabs3 жыл бұрын
spammers, ignore them.
@tyrepwagyi3 жыл бұрын
Thank you so much
@shankarmedhi80743 жыл бұрын
super helpful
@shankarmedhi80743 жыл бұрын
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_K033 жыл бұрын
Thank you
@naveenautomationlabs3 жыл бұрын
You're welcome
@mahatheedandibhotla3 жыл бұрын
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
@ketansoni77773 жыл бұрын
Set has own property of remove duplicates....
@priyakushwaha98652 жыл бұрын
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]