Manafall Daily Quest

String Transformation

Function Name: stringTransform

Description

Write a function named stringTransform that takes two strings as parameters, source and target. The function should determine if it is possible to transform the source string into the target string by replacing one character at a time. At each step, the new string must be in a given dictionary of valid words. The transformation is case sensitive and must use the smallest number of steps possible. The function should return the number of steps required for the transformation. If the transformation is impossible, the function should return -1.

Requirements

  • The function must take exactly two parameters: source (a string) and target (a string).
  • A local dictionary of valid words (array of strings) should be hardcoded into the function.
  • All transformations must occur in the smallest number of steps.
  • Characters replaced in each step must result in a valid word present in the dictionary.
  • The function must be case sensitive, meaning 'a' is different from 'A'.
  • The function should return an integer representing the number of steps required for the transformation, or -1 if it's impossible.
  • The function should have an optimized approach to avoid unnecessary computations.

Examples

Example 1: stringTransform('cat', 'dog') should return 4, if the dictionary is ['cat', 'bat', 'bet', 'bot', 'bog', 'dog'].Example 2: stringTransform('hello', 'world') should return -1, if no valid transformation sequence exists within the dictionary.

Links

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

Balanced Brackets

Mon Dec 02 2024

Write a function that takes a string containing bracket characters ('(', ')', '{', '}', '[' and ']') and checks whether the string contains a balanced set of brackets.A string has balanced brackets if each type of bracket is properly closed and nested within the string.The function should return a boolean indicating whether the input string is balanced.

Prev Quest

Flatten Nested List

Wed Dec 04 2024

Write a function 'flattenList' that takes a single parameter which is a nested list with an unknown level of nesting (i.e., a list where some of the elements can be lists themselves). The function should flatten the nested list, that is, return a single list containing all the elements in the nested structure in their original order, without any nested lists.The function should handle various data types within the nested list, including integers, strings, and other lists. However, the flattened list only needs to preserve the order and the type of the elements; no other operations are required.The input list can have multiple levels of nested lists, but you can assume there are no circular references.Do not use any libraries for this function and ensure that it is written to handle recursive list structures.

Next Quest