Manafall Daily Quest

Path Sum in Binary Tree

Function Name: hasPathSum

Description

In this challenge, you are given the root of a binary tree and an integer target sum. Write a function that checks if the tree has a root-to-leaf path such that adding up all the values along the path equals the target sum.

A leaf is a node with no children.

Your function should return true if such a path is found, or false otherwise.

Requirements

  • The function must be named hasPathSum.
  • The function must take two parameters: the first is a reference to the root node of the binary tree, and the second is an integer representing the target sum.
  • The binary tree nodes have a structure or class with at least two members: an integer value, and references to the left and right child nodes.
  • You may use auxiliary functions if needed.
  • Do not use any built-in tree traversal libraries or functions; write your own traversal code.
  • Assume the tree contains integer values only.

Examples

Given a binary tree and an integer target sum of 22:       5      / \     4   8    /   / \   11  13  4  /  \      \ 7    2      1hasPathSum(root, 22) should return true, as the path 5->4->11->2 sums up to 22.hasPathSum(root, 10) should return false, as there is no root-to-leaf path that sums up to 10.

Links

https://en.wikipedia.org/wiki/Binary_treehttps://en.wikipedia.org/wiki/Tree_traversal

Anagram Checker

Tue Nov 19 2024

The function isAnagram should take two strings as parameters and determine if they are anagrams or not. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. For example, 'listen' is an anagram of 'silent'. The comparison should be case insensitive and ignore all spaces.

Prev Quest

Treasure Hunt Grid

Thu Nov 21 2024

Write a function named 'findTreasure' that navigates through a grid to find a treasure. The grid is represented as a two-dimensional array, where each cell contains a clue to the next cell's position. Each clue is a string in the format 'x,y', indicating the row and column indices of the next cell to check. The treasure is found when a cell points to itself. The function should return the path taken as a list of coordinates (each coordinate being a pair of integers), starting from the top-left cell (0,0). If the treasure cannot be found after visiting all cells, the function should return an empty list.

Next Quest