#262 Removing People with Duplicate Last Names
Write a method that returns the first person for each lastName, removing people with duplicate last names:
public List<Person> distinctPersonsByLastname(List<Person> persons) {
// TODO
}
// Example:
// Ivanov Oleg
// Ivanov Petr
// Petrov Dmitry
//
// Result:
// Ivanov Oleg
// Petrov Dmitry
@RequiredArgsConstructor
@EqualsAndHashCode
@Getter
public class Person {
private final String firstName;
private final String lastName;
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor