Manafall Daily Quest

Matrix Spiral Copy

Function Name: spiralCopy

Description

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.

Requirements

  • The function must handle non-square matrices (different number of rows and columns).
  • The matrix can contain any data type (integers, strings, etc.), but for simplicity, you can assume all elements are integers.
  • You should not use any library functions that simplify the spiral traversal significantly.
  • If the input matrix is empty, the function should return an empty list/array.
  • Optimize the function for readability and efficiency.

Examples

Given the following 2D array:[[1,   2,  3,  4], [5,   6,  7,  8], [9,  10, 11, 12], [13, 14, 15, 16]]Calling spiralCopy(matrix) should return [1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10].

Links

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

Balanced Brackets

Thu Sep 12 2024

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 '{}'.

Prev Quest

LinkedList Merge Sort

Sat Sep 14 2024

In this challenge, you are tasked with implementing a function that performs a merge sort on a singly linked list. The function should be able to sort the elements of the linked list in ascending order, considering that the nodes hold integer values.The merge sort algorithm for a linked list is somewhat similar to merge sort for arrays, but rather than using array indices, you will need to manipulate node references and pointers. Your implementation should be efficient and should not just extract values into an array, sort, and recreate the list.

Next Quest