Skip to content
Search lessons, topics, tests…
Esc

    ↑ ↓ moveEnter openEsc close

    Coding problem

    Active customers, newest first

    EasyAbout 15 minFreeLearn it: Build a readable LINQ report

    The task

    The account manager's page lists the customers who are still active, with the newest sign-ups at the top.

    Complete ActiveNewestFirst(List<Customer> customers). Customer is a record with a Name, whether the customer is Active, and the date the customer Joined. Return the names of the active customers only, the latest Joined date first; customers who joined on the same day are sorted by Name in ascending ordinal order, which compares characters by their numeric values. Do not change the input list. An empty list gives an empty list. The list and its customers are never null, and names hold only lowercase English letters.

    Signature

    public record Customer(string Name, bool Active, DateOnly Joined);
    public static List<string> ActiveNewestFirst(List<Customer> customers)

    Examples

    • [("amy", true, 2026-03-01), ("ben", false, 2026-05-10), ("cara", true, 2026-04-20)] → ["cara", "amy"]. ben is not active, and cara joined after amy.
    • [("zoe", true, 2026-02-02), ("adam", true, 2026-02-02)] → ["adam", "zoe"]. They joined on the same day, so their names decide.

    Limits: Up to 200,000 customers.

    The tests check: an empty list, inactive customers only, one active customer, newest first, the same day sorted by name, dates across years, the date deciding before the name, a short name before a longer one that starts the same way, that the input list is not changed, and 200,000 customers in time.

    Hints

      The solution opens by itself when all tests pass. You remember more if you try first.

      Sign in to see the solution

      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 Customer(string Name, bool Active, DateOnly Joined);
      
      public static class Solution
      {
          // Returns the names of the active customers, newest sign-up first, then by name.
          public static List<string> ActiveNewestFirst(List<Customer> customers)
          {
              throw new NotImplementedException();
          }
      }

      Sign in to run and submit your code. It stays here while you do.