Manafall Daily Quest

Balance Brackets

Function Name: balanceBrackets

Description

Write a function 'balanceBrackets' that takes a string containing only brackets ('{', '}', '(', ')', '[', ']') and determines if the string contains a valid sequence of brackets. A bracket sequence is considered valid if every opening bracket has a corresponding closing bracket and the brackets are properly nested.

Requirements

  • The function must return a boolean indicating whether the input string is balanced.
  • The function should handle an empty string as input and return true, as an empty string is trivially balanced.
  • If the string contains characters other than the aforementioned brackets, the function should return false.
  • You must not use any external libraries or packages.
  • Optimize the function for readability and efficiency.

Examples

balanceBrackets('()[]{}') // returns truebalanceBrackets('([)]') // returns falsebalanceBrackets('{[()]}') // returns truebalanceBrackets('') // returns truebalanceBrackets('[(])') // returns falsebalanceBrackets('{[(])}') // returns falsebalanceBrackets('{[]}()') // returns true

Route Planner

Sat Aug 17 2024

Write a function `findShortestPath` that takes a two-dimensional grid of possible paths and finds the shortest path from the top-left corner to the bottom-right corner. The grid is represented by a 2D array where each element can be 1 (path) or 0 (obstacle). You are only allowed to move right or down. If there is no path to the destination, the function should return null. The function should return the path as a list of coordinates.

Prev Quest

Treasure Map Decoder

Mon Aug 19 2024

You have found an ancient treasure map divided into a grid with each cell containing a number. The number represents the number of steps you need to move from the current cell. You can only move either right or down.Write a function 'decodeTreasureMap' that takes a 2D array representing the map and returns the number of unique paths that lead to the treasure. The treasure is marked with the number 0, and it will only be present once, at the lower-right corner of the grid. You start your journey from the top-left corner of the map. A step must bring you closer to the treasure; therefore, you cannot move left or up.

Next Quest