Coding problem
The cities our customers live in
The task
The delivery team plans its routes from the list of cities its customers live in.
Complete Cities(List<Customer> customers). Customer is a record with a Name and a City. Return each city once, sorted A to Z in ordinal order, which compares characters by their numeric values. The cities come from a form: trim the spaces around each one first, and leave out customers whose city is empty after trimming. Cities are always in lowercase. An empty list gives an empty list. The list, its customers and their cities are never null.
Signature
public record Customer(string Name, string City); public static List<string> Cities(List<Customer> customers)
Examples
[("amy", "pune"), ("ben", "delhi"), ("cara", "pune")]→["delhi", "pune"]. pune is listed once, and the cities are A to Z.[("dev", " goa "), ("eli", ""), ("fay", "goa")]→["goa"]. The spaces around " goa " are trimmed, so it is the same city as "goa"; eli has no city.
Limits: Up to 400,000 customers in up to 100,000 cities.
The tests check: an empty list, one customer, everyone in one city, spaces around a city, an empty city, a city of only spaces, a space inside a city's name, a short city before a longer one that starts the same way, and 400,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 solutionYour code
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, string City);
public static class Solution
{
// Each customer city once, trimmed, without empty ones, sorted A to Z.
public static List<string> Cities(List<Customer> customers)
{
throw new NotImplementedException();
}
}Sign in to run and submit your code. It stays here while you do.