aboutsummaryrefslogtreecommitdiff
path: root/challenge-113/duncan-c-white/README
blob: 6a326449a741ad01c9e9217fa4da75c9e1addf6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Task 1: "Represent Integer

You are given a positive integer $N and a digit $D.

Write a script to check if $N can be represented as a sum of positive
integers having $D at least once. If check passes print 1 otherwise 0.

Example

Input: $N = 25, $D = 7
Output: 0 as there are 2 numbers between 1 and 25 having the digit 7
i.e. 7 and 17. If we add up both we don't get 25.

Input: $N = 24, $D = 7
Output: 1
"

My notes: sounds very simple.  sum ( grep contains 7 )


Task 2: "Recreate Binary Tree

You are given a Binary Tree.

Write a script to replace each node of the tree with the sum of all the remaining nodes.

Example
Input Binary Tree

        1
       / \
      2   3
     /   / \
    4   5   6
     \
      7

Output Binary Tree

        27
       /  \
      26  25
     /   /  \
    24  23  22
     \
     21
"

My notes: so each node's value becomes sum(allnodes) - that node's value
Very tempting to view this as an ascii art -> ascii art problem, last time
we did a similar tree question, I spent a lot of time building the tree
structure, and getting nice layout from print_tree..