Skip to main content

Find Deepest Maximum Element

MIDDLE
LuxoftN-iX

Given a nested array structure, find the maximum element value and return an object with its value and depth level.

Depth is 0-indexed from the root array. If the same maximum appears at multiple depths, return the deepest one.

Example:

Input: [1, [2, [3, 4], 5]]
Output: { value: 5, depth: 1 }

Examples:

Input 1:{"arr":[1,[2,[3,4],5]]}
Output 1:{"value":5,"depth":1}
Input 2:{"arr":[1,2,3]}
Output 2:{"value":3,"depth":0}

Loading editor...

Run your code to see results

Click the Run button above