Problem Β· Hash Table

Dynamic Path Accessor

Learn this problem
● EasyNvidia logoNvidiaOA

Problem statement

Implement get_dict_value for a nested dictionary and a dot-separated path. Each path segment names a key in the current dictionary.

  • If every segment exists, return the value at that path.
  • If a segment is missing, or an intermediate value is not a dictionary, return None.

The runner provides the following parameters:

  • String objJson: a JSON serialization of the source dictionary
  • String path: the dot-separated path to access

Return: A string containing the resolved value as compact JSON text, or None when the path does not exist.

Function

get_dict_value(objJson: String, path: String) β†’ String

Examples

Example 1

objJson = "{\"car\":{\"wheels\":2,\"gears\":5}}"path = "car.gears"return = "5"

The path car.gears resolves to the integer 5. The runner returns its compact JSON representation, 5.

More Nvidia problems

drafts saved locally
public String get_dict_value(String objJson, String path) {
  // write your code here
}
objJson"{\"car\":{\"wheels\":2,\"gears\":5}}"
path"car.gears"
expected"5"
checking account