Route Planner
Function Name: findShortestPath
Description
Write a function `findShortestPath` that takes a two-dimensional grid of possible paths and finds the shortest path from the top-left corner to the bottom-right corner. The grid is represented by a 2D array where each element can be 1 (path) or 0 (obstacle). You are only allowed to move right or down. If there is no path to the destination, the function should return null. The function should return the path as a list of coordinates.
Requirements
- The function `findShortestPath` must take one parameter - a 2D array representing the grid.
- The path, if one exists, should be returned as a list of coordinate tuples in the order they are visited (starting from (0, 0)).
- If no path exists, return null.
- Do not use any external libraries or modules.
- Optimize the function for readability and efficiency.
Examples
Example call: findShortestPath([[1, 0, 1], [1, 1, 1], [0, 1, 1]])Expected output: [(0, 0), (1, 0), (1, 1), (1, 2), (2, 2)]
Links
Area of Polygon
Fri Aug 16 2024
In this challenge, you're required to write a function named `calculatePolygonArea` that calculates the area of a simple polygon. The polygon is defined by its vertices in a 2D plane. The vertices are provided in the form of an array of points, each point being an array with two integers representing the x and y coordinates. It is guaranteed that the vertices are listed in order, either clockwise or counter-clockwise, and the polygon is non-self-intersecting.
Balance Brackets
Sun Aug 18 2024
Write a function 'balanceBrackets' that takes a string containing only brackets ('{', '}', '(', ')', '[', ']') and determines if the string contains a valid sequence of brackets. A bracket sequence is considered valid if every opening bracket has a corresponding closing bracket and the brackets are properly nested.