Skip to content
Search lessons, topics, tests…
Esc

    ↑ ↓ moveEnter openEsc close

    Coding problem

    Tickets per team and priority

    MediumAbout 25 minFull AccessLearn it: Hashing Operators: GroupBy, ToLookup, ToDictionary, CountBy and AggregateBy

    The task

    The support board shows, for each team, how many tickets are still open at each priority.

    Complete OpenTickets(List<Ticket> tickets). Ticket is a record with an Id, a Team, a Priority and whether it is Open. Count the open tickets for each pair of team and priority, and return one TeamCount for each pair that has open tickets. Sort the rows by Team in ascending ordinal order, which compares characters by their numeric values, and within a team by priority from the most urgent: "high", then "medium", then "low". A pair with only closed tickets is left out. An empty list gives an empty list. The list and its tickets are never null, team names hold only lowercase English letters, and the priority is always "high", "medium" or "low".

    Signature

    public record Ticket(int Id, string Team, string Priority, bool Open);
    public record TeamCount(string Team, string Priority, int Open);
    public static List<TeamCount> OpenTickets(List<Ticket> tickets)

    Examples

    • [(1, "web", "low", open), (2, "web", "high", open), (3, "api", "high", closed), (4, "web", "low", open), (5, "api", "medium", open)] → [("api", "medium", 1), ("web", "high", 1), ("web", "low", 2)]. Ticket 3 is closed; within web, high comes before low.
    • [(6, "ops", "high", closed)] → []. A closed ticket is not counted.

    Limits: Up to 400,000 tickets in up to 30,000 teams.

    The tests check: an empty list, closed tickets not counted, a pair with only closed tickets left out, priorities in the order high, medium, low, teams sorted A to Z, the same priority in two teams, and 400,000 tickets in time.

    Hints

      Your code

      C#Solution.csLoading the editor…

      Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;

      public record Ticket(int Id, string Team, string Priority, bool Open);
      public record TeamCount(string Team, string Priority, int Open);
      
      public static class Solution
      {
          // Open tickets per team and priority, teams A to Z, then high, medium, low.
          public static List<TeamCount> OpenTickets(List<Ticket> tickets)
          {
              throw new NotImplementedException();
          }
      }

      This problem comes with TechInterviewNotes Full Access

      Unlock all paid content on TechInterviewNotes.