AlgoMaster Logo
AlgoMasterDesign Support Ticket Routereasy

Design Support Ticket Router

easy

A support desk sends each ticket through a chain of handlers. A specialist accepts tickets in its own category. If it cannot accept a ticket, it passes the ticket to the next handler. The first handler that accepts the ticket returns the response and stops the chain.

The provided SupportDesk exposes this API:

  • SupportDesk() creates a desk with an empty chain.
  • boolean addHandler(String kind) appends "billing", "technical" or "general" to the end of the chain. It returns false for an unknown kind or a kind already present.
  • String chainOrder() returns handler names from head to tail joined by " -> ", or "EMPTY".
  • String route(String category, String subject) sends a ticket into the chain. A successful response is "<HandlerName>: <subject>". If no handler accepts it, return "UNHANDLED". A category other than "billing", "technical" or "general" returns "INVALID" without entering the chain.
  • int handlerCount() returns the number of handlers in the chain.
  • int handledCount() returns the number of tickets successfully handled across all route calls.

The handlers are:

  • BillingSupport accepts only "billing" tickets.
  • TechnicalSupport accepts only "technical" tickets.
  • GeneralSupport accepts every valid ticket, making it a fallback when it appears late in the chain and a catch-all when it appears early.

Complete only the five Chain of Responsibility types left in the starter code:

  • SupportHandler defines name, setNext, getNext and handle.
  • BaseSupportHandler stores the next handler and centralises forwarding. When there is no next handler, forwarding returns "UNHANDLED".
  • BillingSupport, TechnicalSupport and GeneralSupport implement the acceptance rules above.

The supplied desk builds and reports the chain, validates categories, and counts successful routes. SupportDesk is the only type the tests call; do not change it.

Example 1:

Input:

Output:

Explanation: Billing support declines and forwards the ticket. Technical support accepts it and returns immediately, so general support is not reached.

Example 2:

Input:

Output:

Explanation: General support is first and accepts every valid category. The billing handler behind it never sees either ticket.

Constraints

  • 1 <= subject.length <= 80
  • At most 3 handlers are added to one chain.
  • At most 100 calls in total are made across all methods.

How the design is graded

needs 7/10 to pass
  • Chain separation

    Full marks when billing, technical and general support are separate handler classes behind one contract, each handler owns its matching rule, and `route` starts at the head without comparing categories. Lose points heavily when the desk uses conditionals to choose a handler directly or walks the chain and performs the matching itself.

  • First match stops the chain

    Full marks when a specialist forwards only tickets it cannot accept, the general handler accepts every valid ticket, and no handler forwards after producing a response. Lose points when several handlers answer one ticket or when a specialist drops a ticket it cannot handle.

  • Structure and edge cases

    Full marks when handlers are appended in insertion order, unknown and repeated kinds are rejected without changing the chain, an empty chain returns `UNHANDLED`, invalid categories return `INVALID`, and only successful routes increase `handledCount`. Lose points for printing to stdout.

Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.

Hints

Loading...
CallReturns
new SupportDesk()null
addHandler("billing")true
addHandler("technical")true
addHandler("general")true
chainOrder()"BillingSupport -> TechnicalSupport -> GeneralSupport"
route("technical", "Cannot connect to Wi-Fi")"TechnicalSupport: Cannot connect to Wi-Fi"
handledCount()1

Billing support declines the technical ticket and forwards it. Technical support accepts it, so general support is never called.

Run checks these cases. Submit also runs a larger hidden set.