Manafall Daily Quest

Tree Level Sums

Function Name: calculateTreeLevelSums

Description

Write a function that calculates the sum of values at each level of a binary tree.

The function should take the root of the binary tree as an input parameter.

The binary tree nodes have an integer value, along with left and right child pointers.

The function should return an array, where each element represents the sum of the values at the corresponding level of the tree.

Level order traversal of the tree would help to collect the sums in breadth-first manner.

Requirements

  • The function should take a single parameter representing the root of the binary tree.
  • Do not use any built-in tree traversal libraries or frameworks; implement the traversal manually.
  • The input binary tree could be unbalanced.
  • Handle edge cases such as an empty tree, where a returned empty array would be expected.
  • Consider using a queue data structure to implement level order traversal.

Examples

Given the following binary tree structure:     1    / \   2   3  / \   \ 4   5   6The output should be [1, 5, 15] (1 for root level, 2+3 for the second level, and 4+5+6 for the third level).

Links

https://en.wikipedia.org/wiki/Tree_traversal#Breadth-first_searchhttps://en.wikipedia.org/wiki/Binary_tree

Prime Factorization

Mon Sep 16 2024

In this challenge, you are to write a function named calculatePrimeFactors that takes an integer greater than 1 as a parameter and returns a list of its prime factors.Prime factors are the prime numbers that multiply together to equal the original number.The function should return the prime factors in ascending order.

Prev Quest

Fibonacci Nth Number

Wed Sep 18 2024

The Fibonacci sequence is a series of numbers where the next number is found by adding up the two numbers before it. The sequence starts with 0 followed by 1, and each subsequent number is the sum of the previous two.Your task is to write a function named 'fibonacciNth' that calculates the nth number in the Fibonacci sequence.- The function should be efficient and should handle large values of 'n'.- You may not use any libraries or built-in functions that directly compute the Fibonacci sequence. Implement the calculation from scratch using your understanding of the sequence.

Next Quest