An online gaming platform wants to automate its content moderation. Build a system that generates email notifications by summarizing the rule violations that were detected. You are given a list of flagged keywords, and you must group them by category and format them into a structured notification body.
You receive three inputs:
detectedWords: a list of strings, where each string is a keyword the system flagged (for example, ["scam", "cheat", "bot", "cheat"]).categories: a 2D list of strings, where each inner list [<keyword>, <category>] maps one keyword to a violation category (for example, [["scam", "Fraud"], ["cheat", "Gameplay"]]).instructions: a 2D list of strings, where each inner list [<category>, <instruction>] maps one category to a user-facing instruction. The instruction string may contain leading or trailing whitespace that must be removed (for example, [["Fraud", " Financial fraud is prohibited. "]]).Return a list of lists. Each inner list represents a formatted notification for a specific category and contains two strings:
The output must follow these rules:
"Detected Keywords: <keyword1>, <keyword2>,...""Instruction: <instruction_text>", where <instruction_text> is the trimmed version of the original instruction.detectedWords.If any keyword from detectedWords does not appear in the categories mapping, or if detectedWords is empty, the output should be an empty list.
Input:
detectedWords = ["scam", "cheat", "bot"]
categories = [["scam", "Fraud"], ["cheat", "Gameplay"], ["bot", "Gameplay"]]
instructions = [["Fraud", "Financial fraud is prohibited and will result in account suspension"], ["Gameplay", "Unfair gameplay practices detected, please play fairly"]]
Output:
[["Detected Keywords: scam", "Instruction: Financial fraud is prohibited and will result in account suspension"], ["Detected Keywords: bot, cheat", "Instruction: Unfair gameplay practices detected, please play fairly"]]
Explanation:
The word "scam" maps to "Fraud", so the first entry contains "scam" and its instruction. Both "bot" and "cheat" map to "Gameplay", so both appear in the second entry, sorted as "bot", "cheat".
Input:
detectedWords = ["spam", "virus", "grief"]
categories = [["spam", "Communication"], ["virus", "Security"], ["grief", "Behavior"]]
instructions = [["Communication", "Please follow communication guidelines"], ["Security", "Security violation detected"], ["Behavior", "Inappropriate behavior reported"]]
Output:
[["Detected Keywords: spam", "Instruction: Please follow communication guidelines"], ["Detected Keywords: virus", "Instruction: Security violation detected"], ["Detected Keywords: grief", "Instruction: Inappropriate behavior reported"]]
Input:
detectedWords = []
categories = [["test", "Category"]]
instructions = [["Category", "Test instruction"]]
Output:
[]