Manafall Daily Quest

Balanced Brackets

Function Name: isBalanced

Description

Write a function named 'isBalanced' that takes a string containing only bracket characters: '(', ')', '{', '}', '[' and ']', and determines if the input string is balanced. A string is considered balanced if brackets are closed in the correct order and every opening bracket has a corresponding closing bracket.

The function should return true if the input string is balanced, otherwise return false.

Requirements

  • The function isBalanced should accept a single string parameter.
  • The function must handle empty strings (considered balanced).
  • The function must be case-sensitive, considering only the characters mentioned above.
  • No additional or external libraries or packages are allowed; use only the standard features of the language of choice.

Examples

For example, 'isBalanced("(a{b}c)[]")' should return true.'isBalanced("(a{b[c]d}e)")' should return true.'isBalanced("(a{b(c]d}e)")' should return false.'isBalanced("(a{b(c})")' should return false.'isBalanced("")' should return true.

Links

https://en.wikipedia.org/wiki/Balanced_brackets

Binary Tree Paths

Mon Oct 14 2024

Write a function that returns all the paths from the root to leaf nodes in a binary tree. A path is defined as a sequence of nodes starting from the root node and ending at any leaf node. The function should output the paths as an array of string representations, where each string contains the path's nodes' values separated by '->'. Your function should work with any binary tree, not necessarily a binary search tree.

Prev Quest

Find The Town Judge

Wed Oct 16 2024

In a town, there are N people labeled from 1 to N. There is a rumor that one of these people is secretly the town judge.If the town judge exists, then:1. The town judge trusts nobody.2. Everybody (except for the town judge) trusts the town judge.3. There is exactly one person that satisfies properties 1 and 2.You are given an array `trust` where `trust[i] = [a, b]` represents that the person labeled `a` trusts the person labeled `b`.Write a function `findJudge` that finds the town judge's label.The function should take in the parameter `N`, the number of people, and an array of trust pairs, and should return the label of the town judge if they exist or `-1` if they do not.

Next Quest