Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

User-to-Group Mapping for Notifications

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is User-to-Group Mapping for Notifications. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

When a monday notification targets several groups, a user may belong to multiple targeted groups or appear in duplicate mapping records. Implement a function that returns every eligible user exactly once, preserving the order of their first appearance in the mappings.

Exclude the user who triggered the notification, even if that user belongs to a targeted group.

Formal Specification

Implement notification_recipients(mappings, target_groups, sender_id).

  • mappings is a list of two-element lists, where each pair is [user_id, group_id].
  • target_groups is a list of group IDs receiving the notification.
  • sender_id is the user who triggered the notification.
  • Return a list of unique user IDs. A user is included if at least one mapping connects them to a targeted group and they are not the sender.
  • Preserve first-appearance order from mappings.

Constraints

  • 1 <= len(mappings) <= 10^5
  • 0 <= len(target_groups) <= 10^4
  • User and group IDs are hashable values
  • A mapping can be duplicated
  • Return order is based on first appearance in mappings

Function Signature

def notification_recipients(mappings, target_groups, sender_id):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output