← Problems99. Reconcile two sourcesEasyPython
00:00 / 15:00

Reconcile two sources

EasyNot attempted yetAsked at Walmart, Deloitte, TCS

The same figure is loaded from two places and the totals disagree. Before anyone argues about which is right, they need the list of keys that differ.

Input

  • left — a list of (key, value)
  • right — the same, from the other source

Keys are unique within a source.

Output

A list of (key, status) for every key that does not agree, where status is one of:

  • 'ONLY_LEFT' — present on the left, missing on the right
  • 'ONLY_RIGHT' — present on the right, missing on the left
  • 'MISMATCH' — present on both, with different values

Keys that agree are not reported. Order is not graded.

Example

left [('a', 1), ('b', 2)] right [('b', 2), ('c', 3)] returns [('a', 'ONLY_LEFT'), ('c', 'ONLY_RIGHT')]

Constraints

  • Comparing the two sets of keys finds the missing rows and none of the wrong ones. A key present on both sides with a different value is the difference that silently corrupts a report, and it has to be reported.
  • Two sources that agree completely produce an empty list.

Example 1one missing on each side

Input · left
[["a", 1], ["b", 2]]
Input · right
[["b", 2], ["c", 3]]
Output
[["a", "ONLY_LEFT"], ["c", "ONLY_RIGHT"]]

Example 2the sources agree

Input · left
[["a", 1], ["b", 2]]
Input · right
[["a", 1], ["b", 2]]
Output
empty

Topics

joinsanti-joindata quality

Similar problems

Community-reported interview topic. Not an official company question and no affiliation is implied.

solution.py
Loading editor…
Draft not saved yet · Spaces 4 · UTF-8⌘↵ run ⌘⇧↵ submit
Nothing run yet

Run against the public tests, or submit to score against all of them.