Directory diff
MediumOnline Assessment
Compare yesterday's and today's exports of a company directory and list what changed.
Each export is a list of rows "id|name|team|title": four fields separated by |, where id is a whole number without leading zeros and the other three may be empty. Fields never contain |.
Within one export, an id may appear on several rows (the exporter sometimes repeats rows); only the last row for that id counts.
Two values of a field are the same if they are equal after trimming leading and trailing spaces and ignoring upper/lower case, so "Billing " and "billing" are not a change. Everywhere a value is printed, print it trimmed and in its original case, and print an empty value as (none).
Report, for every id that appears in either export:
- in
new_rowsonly:"+ id name"(the new name); - in
old_rowsonly:"- id name"(the old name); - in both with at least one differing field: one line
"~ id field: old -> new"for each differing field, in the ordername,team,title; - in both with no differing field: nothing.
Input: old_rows and new_rows, lists of strings in the format above.
Output: a list of strings with the lines above, ordered by id as a number ascending (9 before 10); the lines of one id stay together in the order given. If nothing changed, return [].
Example 1
- Input:
- [["9|Mia Chen|Billing|Engineer","10|Raj Patel|Sales|AE"],["9|Mia Chen|Platform|Engineer","11|Zoe Park|Sales|AE"]]
- Output:
- ["~ 9 team: Billing -> Platform","- 10 Raj Patel","+ 11 Zoe Park"]
- Explanation
- Id 9 moved from Billing to Platform (only the team line is printed). Id 10 is gone and 11 is new. Ids are ordered as numbers, so 9 comes before 10 and 11.
Example 2
- Input:
- [["4|Lee Wu|ops |Lead","5|Ann|Dev|"],["4|Lee Wu|Dev|Lead","5|Ann B|Dev|Manager","4| Lee Wu|Ops|LEAD"]]
- Output:
- ["~ 5 name: Ann -> Ann B","~ 5 title: (none) -> Manager"]
- Explanation
- Id 4 appears twice in the new export and only the last row counts, so its team is Ops, which equals the old "ops " after trimming and ignoring case; nothing changes there. Id 5 changes both name and title, listed in field order, and the missing old title prints as (none).
Example 3
- Input:
- [["1|Old One|A|B","2|Sam Q|Ops|Lead","3|Tia|Dev|Eng"],["2| sam q |OPS|lead ","3|Tia||Eng","20|Newbie|X|Y"]]
- Output:
- ["- 1 Old One","~ 3 team: Dev -> (none)","+ 20 Newbie"]
- Explanation
- Id 2 is unchanged apart from spacing and case. Id 3 has an empty team in the new export, which prints as (none). Id 1 is only in the old export and id 20 only in the new one; 20 sorts after 3 numerically.
Constraints
0 <= old_rows.length, new_rows.length <= 1,0001 <= id <= 1,000,000; each row has exactly three|separators- Each field is at most 30 characters of letters, digits, spaces and punctuation other than
|