Codepath

Scheduling Conflict

Unit 2 Session 1 (Click for link to problem statements)

U-nderstand

Understand what the interviewer is asking for by using test cases and questions about the problem.

  • Q: What is the problem asking for?

    • A: The problem asks to identify scheduling conflicts between two venues by finding artists who have the same set time in both venues.
  • Q: What are the inputs?

    • A: Two dictionaries, venue1_schedule and venue2_schedule, each mapping artists to their set times.
  • Q: What are the outputs?

    • A: A dictionary containing the key-value pairs that are the same in both input dictionaries.
  • Q: What constitutes a conflict?

    • A: A conflict occurs if an artist is scheduled to perform at the same time in both venues.

P-lan

Plan the solution with appropriate visualizations and pseudocode.

General Idea: Compare the set times of artists in both venue schedules and collect the ones that match.

1) Initialize an empty dictionary `conflicts`.
2) Iterate over each artist and their set time in `venue1_schedule`.
   - Check if the artist is also in `venue2_schedule` and if their set time matches the set time in `venue1_schedule`.
   - If both conditions are met, add the artist and their set time to the `conflicts` dictionary.
3) Return the `conflicts` dictionary.

⚠️ Common Mistakes

  • Ensure that both the artist's presence and their set times are checked.
  • Handle cases where there are no conflicts by returning an empty dictionary.

I-mplement

def identify_conflicts(venue1_schedule, venue2_schedule):
    conflicts = {}
    
    for artist, time in venue1_schedule.items():
        if artist in venue2_schedule and venue2_schedule[artist] == time:
            conflicts[artist] = time
    
    return conflicts
Fork me on GitHub