Coding problem
Apply price updates to the catalogue
The task
Every night the shop merges the day's price updates into its catalogue.
Complete ApplyUpdates(List<Item> catalogue, List<Item> updates). Item is a record with a Code and a Price. Return the new catalogue: one item for every code that is in either list. When a code is in both lists, the item from updates wins; a code only in updates is added; a code only in catalogue stays as it is. Sort the result by Code in ascending ordinal order, which compares characters by their numeric values. Codes match exactly, letter case included. Do not change the input lists. The lists and items are never null, and each code appears at most once in each list.
Signature
public record Item(string Code, decimal Price); public static List<Item> ApplyUpdates(List<Item> catalogue, List<Item> updates)
Examples
catalogue [("A1", 10), ("B2", 20)], updates [("B2", 25), ("C3", 30)]→[("A1", 10), ("B2", 25), ("C3", 30)]. B2 gets its new price, C3 is new, and A1 stays.catalogue [("A1", 10)], updates []→[("A1", 10)]. With no updates, nothing changes.
Limits: Up to 200,000 catalogue items and 100,000 updates.
The tests check: no updates, an empty catalogue, an update winning, a new code added, the result sorted by code, an update with the same price, letter case in codes, that the input lists are not changed, and 200,000 items with 100,000 updates 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 Item(string Code, decimal Price);
public static class Solution
{
// The catalogue with the updates merged in by code (an update wins), sorted by code.
public static List<Item> ApplyUpdates(List<Item> catalogue, List<Item> updates)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.