Skip to content

Latest commit

 

History

History
29 lines (17 loc) · 794 Bytes

File metadata and controls

29 lines (17 loc) · 794 Bytes

Code Challenge 18: Fizz Buzz Tree

Challenge Description

Given a K-ary tree, create a new tree with the same structure as the original but modify the values according to the following

value divisible by 3 >> replace with "Fizz"
value divisible by 5 >> replace with "Buzz"
value divisible by 3 & 5 >> replace with "FizzBuzz"
if divisible by neither >> turn number into string

Approach & Efficiency

Do a preorder traversal, checking each node value as we traverse, and add to the new tree.

Space: O(n)
Time: O(n)

Solution

UML