FastPrepGenerate Unique Company Email Addresses

Generate Unique Company Email Addresses

Marshall Wace logoMarshall Wace● EasyFULLTIMEOA

Problem statement

String S lists employees in order, separated by ; (a semicolon and one space). A full name has a first name, an optional middle name, and a last name.

Build each email address as follows:

  1. Use the first and last names. The middle name does not contribute to the address.
  2. Remove every hyphen from the last name, then keep at most its first eight letters.
  3. Lowercase the first name, shortened last name and company name C. The base address is first.last@company.com.
  4. When that base address has already been assigned, add 2, 3, and so on immediately before @, in the order people appear. The first assignment has no numeric suffix.

Return entries formatted as Original Full Name <email>, joined by ; in the original order. Preserve each complete name exactly as written in S. The assessment emphasizes correctness rather than performance.

Function

solution(S: String, C: String) → String

Examples

Example 1

S = "John Doe; Peter Benjamin Parker; Mary Jane Watson-Parker; John Elvis Doe; John Evan Doe; Jane Doe; Peter Brian Parker"C = "Example"return = "John Doe <john.doe@example.com>; Peter Benjamin Parker <peter.parker@example.com>; Mary Jane Watson-Parker <mary.watsonpa@example.com>; John Elvis Doe <john.doe2@example.com>; John Evan Doe <john.doe3@example.com>; Jane Doe <jane.doe@example.com>; Peter Brian Parker <peter.parker2@example.com>"

The two Parker entries share one base address, while three John Doe entries share another. Middle names remain in the display names but are ignored in the addresses. Removing the hyphen from Watson-Parker and then keeping eight letters gives watsonpa.

Example 2

S = "Ada River; Ada Marie River; Ada Jane River"C = "Example"return = "Ada River <ada.river@example.com>; Ada Marie River <ada.river2@example.com>; Ada Jane River <ada.river3@example.com>"

All three names produce the same base address. The first is unsuffixed, followed by suffixes 2 and 3.

Example 3

S = "ALAN QUINN-SMITH; Alan B Quinn-Smith"C = "EXAMPLE"return = "ALAN QUINN-SMITH <alan.quinnsmi@example.com>; Alan B Quinn-Smith <alan.quinnsmi2@example.com>"

Address comparison uses lowercase normalized names. The original display spelling is preserved, and quinnsmith is shortened to quinnsmi.

Constraints

  • 3 <= S.length <= 1000.
  • 1 <= C.length <= 100, and C contains only English letters.
  • S contains valid two- or three-part names. Parts are separated by spaces; entries are separated by ; .
  • Name parts contain English letters. Only the last name may also contain hyphens.
  • No complete name appears more than once.

More Marshall Wace problems

See Marshall Wace hiring insights
Saved
public String solution(String S, String C) {
    // Write your solution here.
}
S"John Doe; Peter Benjamin Parker; Mary Jane Watson-Parker; John Elvis Doe; John Evan Doe; Jane Doe; Peter Brian Parker"
C"Example"
expected"John Doe <john.doe@example.com>; Peter Benjamin Parker <peter.parker@example.com>; Mary Jane Watson-Parker <mary.watsonpa@example.com>; John Elvis Doe <john.doe2@example.com>; John Evan Doe <john.doe3@example.com>; Jane Doe <jane.doe@example.com>; Peter Brian Parker <peter.parker2@example.com>"
Checking account…