Coding problem
Orders to cities we serve
The task
The courier delivers only to the cities on its service list, so the dispatch screen keeps only the orders it can deliver.
Complete Deliverable(List<Order> orders, List<string> servedCities). Order is a record with an Id and a City. Return the orders whose City is on the service list, in the order of the orders list. Cities match ignoring letter case ("Goa" and "goa" are the same city), but otherwise the whole name must match. The service list may name a city more than once. The lists, orders and city names are never null.
Signature
public record Order(int Id, string City); public static List<Order> Deliverable(List<Order> orders, List<string> servedCities)
Examples
orders [(1, "pune"), (2, "Goa"), (3, "agra")], served ["goa", "pune"]→[(1, "pune"), (2, "Goa")]. Goa matches goa, because letter case is ignored; agra is not served.orders [(4, "delhi")], served []→[]. No city is served.
Limits: Up to 300,000 orders and 100,000 served cities.
The tests check: no orders, no served cities, letter case ignored both ways, orders in their order, a city listed twice on the service list, a city that only starts like a served one, and 300,000 orders against 100,000 cities in time.
Hints
Your 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 Order(int Id, string City);
public static class Solution
{
// The orders whose city is on the service list (letter case ignored), in order-list order.
public static List<Order> Deliverable(List<Order> orders, List<string> servedCities)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.