Manafall Daily Quest

Flatten Nested List

Function Name: flattenList

Description

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.

Requirements

  • The 'flattenList' function must be recursive.
  • The function should handle an arbitrary number of nesting levels.
  • The function should maintain the order of appearance in the nested structure.
  • Avoid using built-in flatten methods if the language provides any. The aim is to create the logic manually.

Examples

If the input list is [1, [2, [3, 4], 5], [6], 7], the function should return [1, 2, 3, 4, 5, 6, 7].Given an input list like ['apple', [3, 4, ['banana']], ['grape', ['pear']]], the output should be ['apple', 3, 4, 'banana', 'grape', 'pear'].

Links

https://en.wikipedia.org/wiki/Recursion_(computer_science)

String Transformation

Tue Dec 03 2024

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.

Prev Quest

Magic Square Checker

Thu Dec 05 2024

A magic square is a grid of numbers where the sum of the numbers in each row, column, and diagonal are all equal. Write a function isMagicSquare that accepts a two-dimensional array (n x n) representing a square matrix, and determines if the matrix is a magic square. The function should return a boolean value - true if the matrix is a magic square, false otherwise. An empty square or a non-square matrix should return false.

Next Quest