KatInterview

Tab-Scoped Ticket Search with Case-Insensitive Matching

StringsAuto-graded · 18 test cases
EasyAuto-gradedStringsstringsfilteringcase-insensitive

Last updated

Filter support tickets by tab, then by a case-insensitive substring match on title or assignee, handling blank queries and unassigned tickets.

A help-desk dashboard shows support tickets in two tabs: unresolved and archived. Above the list is a search field. Implement the function that decides which tickets are visible for a given tab and search text.

Input

  • tickets: a list of dictionaries. Each ticket may contain:
    • "id": an identifier (not used for matching)
    • "status": a string, normally "unresolved" or "archived"
    • "title": a string
    • "assignee": a string, or None if the ticket is unassigned
  • tab: the name of the tab currently shown
  • search_text: the raw text typed into the search field

Task

Return the tickets that should be visible, as a list.

A ticket is visible when all of the following hold:

  1. Tab: tab is one of "unresolved" or "archived" (compared ignoring letter case), and the ticket's status equals the tab, again ignoring letter case. If tab is not one of these two names, return an empty list.
  2. Search: Let the query be search_text with leading and trailing whitespace removed.
    • If the query is empty, the search imposes no restriction.
    • Otherwise the query must appear as a contiguous substring, ignoring letter case, either in the ticket's title or in its assignee name. The substring can appear anywhere, not only at the start of a word.

Details:

  • A ticket with assignee equal to None (or with no assignee key) has no assignee text to match, so only its title can match a non-empty query.
  • A ticket with no title key is treated as having an empty title.
  • Whitespace inside the query is significant and is not altered. Only the ends are trimmed.
  • Return the original ticket dictionaries, unmodified, in the same relative order as in tickets.
  • Do not modify the input list.

Constraints

  • 0 <= len(tickets) <= 10^4
  • Titles and assignee names are at most 200 characters.
  • search_text is at most 200 characters.
  • Case-insensitive comparison should use Unicode-aware case folding (Python's str.casefold).

Examples

Example 1

Input: select_visible_tickets([{'id': 1, 'status': 'unresolved', 'title': 'Login failure', 'assignee': 'Alice'}, {'id': 2, 'status': 'unresolved', 'title': 'Billing question', 'assignee': 'Bob'}, {'id': 3, 'status': 'archived', 'title': 'Old login issue', 'assignee': 'ALICIA'}], 'unresolved', 'LOGIN')

Output: [{'id': 1, 'status': 'unresolved', 'title': 'Login failure', 'assignee': 'Alice'}]

Example 2

Input: select_visible_tickets([{'id': 1, 'status': 'unresolved', 'title': 'Cannot export report', 'assignee': None}, {'id': 2, 'status': 'unresolved', 'title': 'Password reset', 'assignee': 'Dana'}, {'id': 3, 'status': 'archived', 'title': 'Export fixed', 'assignee': 'Dana'}], 'unresolved', ' ')

Output: [{'id': 1, 'status': 'unresolved', 'title': 'Cannot export report', 'assignee': None}, {'id': 2, 'status': 'unresolved', 'title': 'Password reset', 'assignee': 'Dana'}]

Example 3

Input: select_visible_tickets([{'id': 1, 'status': 'unresolved', 'title': 'Slow dashboard', 'assignee': 'Evan'}, {'id': 2, 'status': 'archived', 'title': 'Slow import', 'assignee': 'Fiona'}], 'archived', 'fIo')

Output: [{'id': 2, 'status': 'archived', 'title': 'Slow import', 'assignee': 'Fiona'}]

Hints

Hint 1

Normalize first: compute the folded tab name and the trimmed, folded query once, outside the loop over tickets.

Hint 2

Handle the cheap rejections early: an unknown tab means an empty result, and a ticket whose folded status differs from the folded tab is skipped.

Hint 3

For the search, treat a missing or None assignee as an empty string, then check whether the folded query is a substring of the folded title or the folded assignee. An empty query should match everything in the tab.