5082

Almost the Same Customer

Algorithm
Hard
Pro
fuzzy-matching
edit-distance
normalization
performance

Almost the Same Customer

After a CRM import your customer master is littered with near-duplicates: "Nordwind Handelskontor GmbH" sits next to "Nordwind Handelsokntor", and "ACME industrial holdings Ltd." next to "Acme Industrial Holdings GmbH & Co. KG". You are building the matching engine that finds these pairs — a normalization pre-pass, a typo-aware edit distance, and a pair scan that survives a 300-row candidate list without comparing everything against everything.

Requirements

The starter includes two tables that the tests bind to — submit them unchanged:

  • table "Name Match Candidate": "Entry No." (Integer, primary key), Name (Text[100]);
  • table "Name Match Pair": "Entry No. 1", "Entry No. 2" (Integer, composite primary key), Similarity (Decimal).

Create a codeunit named "Fuzzy Customer Match" with five public procedures:

procedure NormalizeName(Name: Text): Text
procedure EditDistance(Left: Text; Right: Text): Integer
procedure Similarity(NameA: Text; NameB: Text): Decimal
procedure FindDuplicates(var Candidate: Record "Name Match Candidate"; Threshold: Decimal; var MatchPair: Record "Name Match Pair")
procedure GetScoredPairCount(): Integer

NormalizeName

Apply these steps in order:

  1. Uppercase the whole name.
  2. Replace every character that is not A–Z or 0–9 with a space (this includes punctuation like ., ,, &, -, ').
  3. Collapse every run of spaces into a single space and trim leading and trailing spaces, so the result is space-separated words.
  4. While the name still has at least two words and its last word is one of the legal-form words AG, APS, BV, CO, CORP, GMBH, INC, KG, LLC, LTD, OY, PLC, SA, SARL, drop that last word — repeatedly, so "Acme GmbH & Co. KG" becomes "ACME" one word at a time.

Legal-form words anywhere else stay: "Ltd Tools Ltd" normalizes to "LTD TOOLS", and a name that consists of nothing but a single legal-form word stays as itself ("GmbH" → "GMBH").

The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
Pro problem

Solve it with Pro

You’re reading the opening of the statement. Pro unlocks the whole problem:

  • The full statement
  • Starter code in the browser editor
  • 13 grading tests, run on Business Central 28.5
  • 3 hints
  • The reference solution

Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.

$10 / month
or $100 / year
Upgrade
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade