UBER | Phone Screen | L5A | San Francisco

Anonymous User
1201
Jun 27, 2022

Question asked for Uber Java Software Engineering Position(Phone Interview):

Convert json (with constraints) to csv

Input

[
{
			"f1": "v1",
			"f2": [{"f3": "v2"}, "v3"],
			"f4": {"f5": ["v4", {"f6": "v5"}], "f7": "v6"},
            "f8": ["v7", "v8", "v9", ["v10"]]

	},
{
			"f1": "a1",
			"f2": [{"f3": "a2"}, "a3"],
			"f4": {"f5": ["a4", {"f6": "a5"}], "f7": "a6"},

	},
]

Output:

f1, f2.f3, f2, f4.f5, f4.f5.f6, f4.f7
v1, v2, v3, v4, v5, v6
a1, a2, a3, a4, a5, a6

...

Constraints

  • The key names are the same in all nested dictionaries.
  • The values are different across dictionaries.
  • The keys can be in any order in the output as long as the corresponding values are mapped to the keys.
  • There is no limit to the nesting depth and there can be any arbitrary combinations of lists, dictionaries and strings.
Comments (4)