Back to problems

Get Nested Object by Path

Algorithm · Amazon · Medium

Requirements You receive a deeply nested combination of Map values and Array values together with a path expression. A path may use dot-separated property names (x.y.z) as well as bracketed array positions (x[0], including consecutive brackets such as m[3][8]). Produce the item reached by the path. If traversal cannot continue because a portion is absent, use a chosen failure convention (undefined, null, or an exception); clarify the expected convention with the interviewer.…

Checking your access…