Manafall Daily Quest

Balanced Brackets

Function Name: isBalancedBrackets

Description

In many programming languages, brackets must all be correctly paired for code to be properly processed. A string of characters is said to be balanced if each opening bracket has a corresponding closing bracket of the same type and brackets are properly nested. Write a function to determine if a given string of brackets is balanced. The function should support parentheses '()', square brackets '[]', and curly braces '{}'.

Requirements

  • The function should take a single parameter: a string consisting solely of brackets '()', '[]', and '{}'.
  • The function should return a boolean value: true if the string is balanced, false otherwise.
  • A balanced string has each opening bracket paired and nested correctly with a corresponding closing bracket of the same type.
  • Brackets cannot overlap improperly, e.g., '(]' is not balanced.
  • An empty string should be considered balanced.
  • You can assume that there will be no characters other than brackets.

Examples

if isBalancedBrackets('([]){()}') then return true end -- should return true because the string is balanced.if isBalancedBrackets('[(]{)}') then return false end -- should return false because the string is not balanced.if isBalancedBrackets('') then return true end -- should return true because an empty string is balanced.

Links

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

RLE Compression

Wed Sep 11 2024

Write a function 'runLengthEncode' that takes a string and compresses it using the basic form of Run Length Encoding (RLE).Run Length Encoding is a simple form of lossless data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count.Your function should return the compressed string where consecutive instances of the same character are replaced by one instance of the character followed by the number of repeated occurrences.If a character does not repeat, it should be left as-is and not followed by a number.The function should handle empty strings properly.

Prev Quest

Matrix Spiral Copy

Fri Sep 13 2024

Write a function 'spiralCopy' that takes a 2D array (a matrix) as an input and returns a list (or array) of its elements in spiral order. Spiral order starts at the top-left corner of the two-dimensional array, goes to the right, and proceeds in a spiral pattern all the way until every element has been visited.

Next Quest