Algorithm · Karat · Medium
You are given a list of pairs of the form (parent, child). Each pair states that the first person is a parent of the second. Using these relationships, solve the following tasks in turn: Determine which people are parents, and which children have exactly one parent. Given two people, decide whether they have at least one ancestor in common. Given a person, find that person's earliest known ancestor. Examples Example 1 Example 2