Coding problem
New, lost and kept customers
The task
The monthly report compares last month's buying customers with this month's, by email address.
Complete Compare(List<string> lastMonth, List<string> thisMonth). Each list holds the email addresses of the customers who bought that month. Emails match ignoring letter case, so "Ben@x.com" and "ben@x.com" are the same customer, and a month may list an email more than once. Return a CustomerChanges with three lists: New holds the emails of this month that were not in last month, Lost the emails of last month that are not in this month, and Kept the emails in both. Write each email in lowercase and only once, and sort each list in ascending ordinal order, which compares characters by their numeric values. The lists and emails are never null, and emails hold only English letters, digits, "@" and ".".
Signature
public record CustomerChanges(List<string> New, List<string> Lost, List<string> Kept); public static CustomerChanges Compare(List<string> lastMonth, List<string> thisMonth)
Examples
last ["amy@x.com", "Ben@x.com"], this ["ben@x.com", "cara@x.com"]→(New ["cara@x.com"], Lost ["amy@x.com"], Kept ["ben@x.com"]). Ben@x.com and ben@x.com are the same customer, who stayed.last [], this ["dev@x.com", "DEV@x.com"]→(New ["dev@x.com"], Lost [], Kept []). The same email twice counts once.
Limits: Up to 200,000 emails in each month.
The tests check: two empty months, repeated emails, letter case not making a new customer, each list sorted, everyone kept, everyone new, everyone lost, and 200,000 emails a month 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 CustomerChanges(List<string> New, List<string> Lost, List<string> Kept);
public static class Solution
{
// New, lost and kept customers between two months, emails compared and returned in lowercase, each list A to Z.
public static CustomerChanges Compare(List<string> lastMonth, List<string> thisMonth)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.