Manafall Daily Quest

Pathfinder

Function Name: findShortestPath

Description

Implement a function 'findShortestPath' that takes a grid (2D array) consisting of '0's (empty spaces), '1's (walls), 'S' (start), and 'E' (end).

The function should return an integer representing the length of the shortest path from 'S' to 'E' that only passes through empty spaces ('0').

If no path exists, the function should return -1.

The path can only move horizontally or vertically, not diagonally.

Requirements

  • The 'findShortestPath' function must handle grids of any size.
  • Walls ('1's) cannot be part of the path.
  • The grid will contain one 'S' and one 'E'.
  • The grid will only consist of '0', '1', 'S', and 'E'.
  • Do not use any built-in pathfinding libraries.
  • Optimize the function for readability, not just performance.

Examples

Given the following grid:grid = [  ['S', '0', '1', '0'],  ['0', '1', 'E', '0'],  ['0', '0', '0', '0'],  ['1', '1', '0', '1']]findShortestPath(grid) should return 3.

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.

Prev Quest

Matrix Spiral

Sat Dec 07 2024

Write a function that takes an m x n matrix of integers as an input and returns a list of the matrix's elements in spiral order. Spiral order starts at the top-left corner of the matrix, goes to the right, and proceeds in a spiral pattern all the way until every element has been visited.

Next Quest