Company: THOUGHT WORKS
Difficulty: medium
Problem Statement: You are given a root of a binary tree whose value is N. The rule to generate the children of the tree from p is: c1 = p - 1 and c2 = p - 2, where c1 and c2 are children of parent p and c1 >= 1 and c2 >= 1. For example, if N = 4, the tree generated gives the tree: 4 / \ 3 2 / \ / 2 1 1 / 1 Your task is to find the total occurrences of node i, where 1 <= i <= N. For the above example, the answer is: freq(1) = 3