This is a verified interview question from Lseg---london-stock-exchange. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Priority-Aware Ticket Assignment - LSEG London Stock Exchange Online Assessment RNS Institute" covers key patterns like Arrays.
"# Task 2 You are given a set of support tickets and a set of analysts. Each ticket belongs to a domain, has a required complexity, and has a priority. Each analyst supports one or more domains and has a maximum complexity level they can handle. Tickets must be assigned to analysts subject to the following rules: 1. An analyst can handle a ticket only if: - the analyst supports the ticket's domain, and - the analyst's skill/complexity level is at least the ticket's complexity. 2. Each analyst can be assigned to at most one ticket. 3. Tickets are processed in priority tiers in the order: `P1`, then `P2`, then `P3`. 4. Within each priority tier, the final maximum matching size must be independent of the order in which tickets are processed. 5. Augmenting paths/reassignments are allowed. A ticket already assigned to an analyst may be moved to another compatible analyst if this allows another ticket to be assigned. 6. Priority is strict: a match in a higher-priority tier must not be sacrificed to increase the number of matches in a lower-priority tier. 7. Therefore, maximize the number of assigned `P1` tickets first. Subject to that, maximize `P2`, and finally maximize `P3`. 8. The output must contain the number of assigned tickets for each priority: `[p1_assigned, p2_assigned, p3_assigned]`. ## Input `tickets` is an array where each ticket is: `[ticket_id, domain, complexity, priority]` where: - `ticket_id` is a unique string. - `domain` is a string. - `complexity` is an integer from 1 to 5. - `priority` is one of `"P1"`, `"P2"`, `"P3"`. `analysts` is an array where each analyst is: `[analyst_id, supported_domains, skill]` where: - `analyst_id` is a unique string. - `supported_domains` is a non-empty list of domain strings. - `skill` is an integer from 1 to 5. ## Constraints - `0 <= len(tickets) <= 40` - `0 <= len(analysts) <= 40` - `complexity` and `skill` are integers in `[1, 5]`. - Each analyst supports at least 1 and at most 6 distinct domains. - `priority` is exactly one of `"P1"`, `"P2"`, `"P3"`. - `ticket_id`, `analyst_id`, and every domain name are single whitespace-free tokens. ## Examples ### Example 1 ```text tickets = [ ["T1", "network", 2, "P1"], ["T2", "security", 3, "P2"], ["T3", "network", 1, "P3"] ] analysts = [ ["A1", ["network", "security"], 3], ["A2", ["network"], 2] ] Output: [1, 1, 0] ``` Explanation: For P1, T1 can be assigned to either A1 or A2. Suppose it is assigned to A1. For P2, T2 requires `security`, so only A1 can handle it, but A1 is already assigned. An augmenting path can reassign T1 from A1 to A2, freeing A1 for T2. Thus: - T1 -> A2 - T2 -> A1 Both P1 and P2 are assigned. T3 cannot be assigned because both analysts are occupied and no augmenting path can increase the total without reducing the higher-priority assignment. Result: `[1, 1, 0]`. ### Example 2 ```text tickets = [ ["T1", "network", 1, "P1"], ["T2", "security", 1, "P1"], ["T3", "network", 1, "P3"] ] analysts = [ ["A1", ["network", "security"], 5], ["A2", ["network"], 5] ] Output: [2, 0, 2] ``` Explanation: Both P1 tickets can be matched: - T1 -> A2 - T2 -> A1 Therefore the maximum P1 count is 2. No analyst remains for T3, so the final result is `[2, 0, 0]` if assignments are strictly exclusive across all priority tiers. If the intended specification permits lower-priority rematching after fixing the maximum P1 count, then the expected result is `[2, 0, 0]`; the implementation must follow the strict-priority rule described above. ## Important Requirement A simple greedy strategy such as: ```text for each ticket: assign the first free compatible analyst ``` is not sufficient. You must support reassignment using augmenting paths so that the maximum possible number of tickets is assigned within each priority tier. For example, assigning a flexible P1 ticket to A1 may prevent a security P1 ticket from being assigned. The algorithm should be able to move the first ticket to another compatible analyst. ## Expected Function Implement a function that receives `tickets` and `analysts` and returns: ```text [p1_assigned, p2_assigned, p3_assigned] ``` The exact function signature depends on the language starter code."
Join thousands of developers practicing for Lseg---london-stock-exchange.