#520 Sum of Binary Tree Leaves

Companies:
Sberbank
Themes:
AlgorithmsTreesPractice

Implement a binary tree Node with integer node values. Implement a sum method that accepts a tree and returns the sum of its leaf values.

Example tree:

    3
   / \
  1   2
 /
4

Leaves: 2 and 4
Answer: 2 + 4 = 6
class Main {

    public static void main(String[] args) {
        ...
    }

    static class Node {
        static int sum(Node node) {
            ...
        }
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in