IBMOA #10
Prediction Diff (JSON Key Recommendations)
Estimated EasyJudge-ready
Compare two JSON objects and return the top-level keys that exist on only one side or whose values differ between the two sides, in ascending lexicographic order of Unicode code points. Object key order does not affect equality, arrays are ordered, a bool differs from a number, and a missing key differs from null; numbers are compared by their exact decimal value.
Input
The input is exactly two lines of JSON objects, optionally followed by one final newline; CRLF is supported. On this site the total UTF-8 size is ≤4MiB; each root has ≤1000 keys, each tree has ≤10000 value nodes, and container depth is ≤20 (the root counts as 1); every key is ≤64 code points, and string values are ≤256 code points and may be empty; text must consist of valid Unicode scalar values, and duplicate keys are rejected. Full JSON values are supported: object/array/string/number/bool/null. Numbers have absolute value ≤10^9 and are integer multiples of 10^-6, a number token is ≤64 characters, the absolute value of the exponent is ≤12, and equivalent decimal, exponent and −0 forms are supported.
Output
Output a JSON array of strings in ascending order with no duplicates; equivalent encodings with whitespace and valid escapes are allowed.
Example 1
Input:
{"hacker":"rank","input":"output"}
{"hacker":"ranked","input":"wrong"}
Output:
["hacker", "input"]
Example 2
Input:
{"a":null,"b":true}
{"b":1}
Output:
["a", "b"]
Example 3
Input:
{"a":1e-6,"b":-0,"c":{"x":1,"y":2}}
{"a":0.000001,"b":0.0,"c":{"y":2.0,"x":1}}
Output:
[]
Example notes
The examples give ["hacker","input"], ["a","b"] and [] respectively; different number formats do not count as a difference.
Editorial
Loading solution…