#155 Unique People by Full Name

Companies:
Sberbank
Themes:
JavaCollections & GenericsHash TablesPractice

Implement unique():

@Data
@AllArgsConstructor
public class Person {
    public Integer id;
    public String firstName;
    public String secondName;
    public String patronymicName;
}

@Test
public void test() {
    List<Person> persons = new ArrayList<>();
    persons.add(new Person(1,"Ivan","Vasya","Petr"));
    persons.add(new Person(2,"Ivan","Vasya","Petr"));
    persons.add(new Person(3,"Ivan","Vasya","Petr"));
    persons.add(new Person(4,"Ivan","Gupta","Ivan"));
    persons.add(new Person(5,"Petr","Rama","Igor"));
    Collection<Person> uniquePersons = unique(persons);
    assert uniquePersons.size() == 3;
}

// Unique collection by the combination of firstName, secondName, and patronymicName
public static Collection<Person> unique(List<Person> persons){
    ...
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in