E-commerce Notification Router
Problem statement
Implement the routing decision for a batch of e-commerce notifications. For notification i, preferredChannels[i] is the user's preferred channel and priorities[i] is either NORMAL or URGENT.
- A
NORMALnotification routes only to the user's preferred channel. - An
URGENTnotification routes to all channels in the fixed orderEMAIL,SMS,PUSH.
Return one channel array per notification. Implement only the routing decisions; delivery handlers and delivery success are outside this task.
Function
routeNotifications(preferredChannels: String[], priorities: String[]) → String[][]Examples
Example 1
preferredChannels = ["EMAIL","SMS","PUSH"]priorities = ["NORMAL","URGENT","NORMAL"]return = [["EMAIL"],["EMAIL","SMS","PUSH"],["PUSH"]]The normal notifications use their preferences, while the urgent notification is sent through all three routing channels.
Example 2
preferredChannels = ["PUSH"]priorities = ["URGENT"]return = [["EMAIL","SMS","PUSH"]]Urgency overrides the preferred channel and selects every channel in canonical order.
Example 3
preferredChannels = ["SMS","EMAIL"]priorities = ["NORMAL","NORMAL"]return = [["SMS"],["EMAIL"]]Each normal notification produces exactly one route.
Constraints
1 <= preferredChannels.length == priorities.length <= 10^5.- Every preferred channel is
EMAIL,SMS, orPUSH. - Every priority is
NORMALorURGENT.