We don't need repeats

  • 10
  • Locked
It's difficult to imagine a situation where you might need the program we're going to ask you to write. However, small modifications can make it practical. You can also imagine it as part of something larger, such as a search engine. Let's create a dictionary, fill it with (last name, first name) entries, and then remove people with the same first name.
You can't complete this task, because you're not signed in.
Comments (34)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Level 19 , Kyiv, Ukraine
12 July 2022, 10:52
It was hard. Hint: all for() loops must be on duplicates
P.B.Kalyan Krishna
Level 22 , Guntur, India
4 July 2022, 10:15
This one I can't understand. Requirement number 4 clearly states that the removeFirstNameDuplicates() must remove from the map ALL the people who have the SAME first name. That is all the people not just duplicates. Yet it fails to validate when I do this. It validates correctly only if we remove the duplicates. This is a bit misleading, the wording of the requirements.
Level 10 , Brazil
17 April 2022, 21:13
I made a "hadouken" to solve it. Make a copy for the original map and to much fors and ifs, the ugliest way, but it works.
Alexandre Desbois
Level 10 , Chamarandes-Choignes, France
27 December 2021, 07:19
I found it easier than the other difficult ones. I created two HashMap in removeFirstNameDuplicates, one copy of the map to iterate through it without having problems when we would remove elements from the original map and another to add the dupplicates in it. Then it's pretty straightforward.
carlos oliveira
Level 10 , Seattle, United States
20 November 2021, 03:38
-SUPER HINTS: - Only pass the "duplicated values" to removeItemFromMapByValue() method otherwise it will remove everithing. - when removing ((keep the method 1º parameter, and replace the 2º paramenter with the "key or value" that it's duplicated)) - remember: passing the node/set view/keyset won't work for the first parameter
Richard Caputo
Level 16 , United States of America
17 September 2021, 19:46
Biggest mistake I made was forgetting that ALL KEYS of a hashmap are unique.
Level 15 , Old Town, United States
30 April 2021, 02:59
As someone mentioned, do look up Collections.frequency. It will make your life much more pleasant. Happy coding! :)
ziv fisher
Level 9 , Petah Tikva, israel
12 October 2020, 20:36
This was fun and challenging!
Karas Java Developer
27 September 2020, 23:26
Couple of hints: The removeByValue Method will remove from the map any name passed in it as a value, NOTE: you are passing a map and a string. Second, remember you can not remove from the same map you are iterating. In few words, find out how many times a first name repeats, then remove those repeated more than 1. It is that simple
Level 10 , Dresden, Germany
13 June 2021, 19:41
Thank you, this is a perfect summary of the recipe to solve (if not to love) this very very challenging task! 👍👍👍
Level 23 , Columbia, United States
25 July 2020, 01:02
First answer I ever copy pasted. I gotta study up on HashMaps.
Joe M
Level 47 , Owings Mills, United States
3 January 2021, 18:27
Alex Lee youtube video on HashMaps was helpful for me. https://www.youtube.com/watch?v=70qy6_gw1Hc