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

Поделиться
HTML-код
  • Опубликовано: 15 янв 2025
  • НаукаНаука

Комментарии • 47

  • @ashokanumandla1280
    @ashokanumandla1280 3 года назад +10

    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 года назад +1

      Yeah correct :)

    • @shaileshchauhan7043
      @shaileshchauhan7043 3 года назад +1

      @@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.

  • @crickettales6594
    @crickettales6594 3 года назад +3

    What a series of questions you are posting🎉🎉

  • @paladarsh39
    @paladarsh39 3 года назад +2

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

  • @ankitkatewa2943
    @ankitkatewa2943 3 года назад +3

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

  • @ramkishore3768
    @ramkishore3768 3 года назад +2

    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 года назад +2

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

  • @aayushpatel3360
    @aayushpatel3360 3 года назад

    mast hai sir aapka ye series. Thank You so much

  • @rubeenas2004
    @rubeenas2004 3 года назад +1

    You are The Best!!!!!!!!

  • @pradeepvanahalli2279
    @pradeepvanahalli2279 3 года назад

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

  • @dp_prajapati
    @dp_prajapati 3 года назад

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

  • @pandudamera7211
    @pandudamera7211 3 года назад +1

    Thank you a lot brother

  • @Wermax23
    @Wermax23 3 года назад +2

    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);
    }

  • @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👍

  • @kattasrihari7332
    @kattasrihari7332 3 года назад +1

    Very good content

  • @phanirajkumarvidiyala8448
    @phanirajkumarvidiyala8448 3 года назад

    super good explanation

  • @sudipmitra292
    @sudipmitra292 3 года назад +1

    Really helpful

  • @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

  • @sais2218
    @sais2218 3 года назад +1

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

  • @Baigan42
    @Baigan42 3 года назад +1

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

  • @tyrepwagyi
    @tyrepwagyi 3 года назад

    Thank you so much

  • @Poornima_K03
    @Poornima_K03 3 года назад +1

    Thank you

  • @tajindersingh6519
    @tajindersingh6519 3 года назад

    Good one Naveen!!!

  • @rohitagarwal2601
    @rohitagarwal2601 3 года назад +2

    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.

  • @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?

  • @shankarmedhi8074
    @shankarmedhi8074 3 года назад

    super helpful

  • @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);

  • @akshayaamar9825
    @akshayaamar9825 3 года назад +1

    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);
    }

  • @Gaurav12081
    @Gaurav12081 3 года назад

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

  • @AsifIquebalSarkar
    @AsifIquebalSarkar 3 года назад +1

    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

  • @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??

  • @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

  • @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

  • @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

  • @amolmehlawat8197
    @amolmehlawat8197 3 года назад +1

    SOLID principles sir. 😓

  • @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]