Interview Query

Pool Matching

0
Have you seen this question before?

You’re given a list of people to match together in a pool of candidates.

We want to match up people based on two ways:

  1. A hard filter on scheduled availability

  2. A closest match based on similar interests

Example:

Input:

people = [
    {
        'name': 'Bob',
        'availability': ['2021-01-10', '2021-01-11'],
        'interests': ['rock climbing', 'tech', 'data science'],
    },
    {
        'name': 'Joe',
        'availability': ['2021-01-10', '2021-01-09'],
        'interests': ['rock climbing', 'swimming', 'data science'],
    },
    {
        'name': 'Carolyn',
        'availability': ['2021-01-11', '2021-01-12'],
        'interests': ['data science'],
    },
    {
        'name': 'Dan',
        'availability': ['2021-01-12'],
        'interests': ['rock climbing'],
    },
]

In this scenario, we would return a match of Bob and Joe while also matching Carolyn and Dan. Even though Carolyn and Dan don’t have any interest overlap, Carolyn is the only one with availability to meet Dan’s schedule.

The goal is to optimize on total number of matches first while then subsequently optimizing on matching based on interests

Write a function given the formatted list of dictionaries above to return a list of matches along with scheduled times. If there is an odd number or excess people that cannot be matched based on availability, return them in a separate list with their existing values. 

Output:

matches = [
    {
        'match': ('Bob', 'Joe'),
        'scheduled_date': '2021-01-10',
        'overlapping_interests': ['rock climbing', 'data science'],
    },
    {
        'match': ('Carolyn', 'Dan'),
        'scheduled_date': '2021-01-12',
        'overlapping_interests': []
    },
]

no_matches = []
Next question: Losing Users
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code