Deepest Leaves Sum Problem
Deepest Leaves Sum Problem — ExecCode Hard DSA Practice
Solve the Deepest Leaves Sum problem on ExecCode. Free online hard DSA practice in Tree. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description Imagine you're solving Deepest Leaves Sum in a real system where you must be correct and efficient. Problem Given the root of a binary tree represented as an array in level-order where null denotes a missing child, compute the sum of the values of the tree's deepest leaves. The input is a single line containing the tree in bracketed array format (e.g. [1,2,3,null,4]). Input Format A single line: the tree as a level-order array (bracketed), e.g. "[1,2,3,4,5,6,7]". Use the literal token null for absent children. Output Format A single integer: the sum of all node values at the maximum depth (the deepest level) of the tree. Constraints The array represents a binary tree in level-order. Child positions for missing nodes are filled with null. Node values are integers.
Examples
Input {"data": "[1,2,3,4,5,6,7]"}; Output 22. Input {"data": "[6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]"}; Output 19. Input {"root": [1, 2, 3, 4, 5, null, 6, 7, null, null, null, null, null, 8]}; Output 8
Constraints
1<=N<=10^4
Practice Deepest Leaves Sum free on ExecCode. Browse DSA problems, topic map, and placement guides.