Manafall Daily Quest

Balanced Parentheses

Function Name: checkBalancedParentheses

Description

Write a function called 'checkBalancedParentheses' that takes a string containing only parentheses (i.e., '(', ')', '[', ']', '{', '}') and determines if the parentheses in the string are balanced. A string has balanced parentheses if each type of parenthesis is closed in the correct order. You may ignore any characters other than the six valid parentheses characters.

Requirements

  • The function should return true if the string has balanced parentheses, otherwise return false.
  • Do not use any built-in functions, except for those that are essential like string length, indexing and comparison operators.
  • The function should handle an empty string as input, considering it as balanced.
  • The function must be able to handle an arbitrary length of input string.
  • Your solution should have a linear run-time complexity, i.e., O(n).

Examples

Example 1: checkBalancedParentheses('(([]){})') should return true.Example 2: checkBalancedParentheses('({[}])') should return false.Example 3: checkBalancedParentheses('') should return true.Example 4: checkBalancedParentheses('[[{{(())}}]]') should return true.Example 5: checkBalancedParentheses('([(]))') should return false.

Links

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

Flatten Nested Dictionary

Thu Oct 03 2024

Write a function 'flattenDictionary' that takes as input a dictionary with nested dictionaries and returns a flat version of it (a dictionary with no nested dictionaries).Keys in the flattened dictionary should be composed of the keys from the original nested dictionaries, joined with a '.' (period).If a certain key has an empty dictionary as its value, then just represent the key with an empty object in the flattened dictionary.The function should handle an arbitrary level of nesting.

Prev Quest

Frequency Counter

Sat Oct 05 2024

Write a function that takes a string as its only parameter. Your function should return a mapping of each unique character to its frequency in the string. The frequency is defined as the number of times a character appears in the string. The function should ignore casing, meaning that 'a' and 'A' are considered the same character, and spaces and punctuation should be ignored. Your solution should not use any third-party libraries and should optimize for readability and efficiency.

Next Quest