Treasure Map Decoder
Function Name: decodeTreasureMap
Description
You have found an ancient treasure map divided into a grid with each cell containing a number. The number represents the number of steps you need to move from the current cell. You can only move either right or down.
Write a function 'decodeTreasureMap' that takes a 2D array representing the map and returns the number of unique paths that lead to the treasure. The treasure is marked with the number 0, and it will only be present once, at the lower-right corner of the grid. You start your journey from the top-left corner of the map. A step must bring you closer to the treasure; therefore, you cannot move left or up.
Requirements
- The function should take a single argument: a 2D array (list of lists) representing the treasure map grid.
- Each cell contains an integer. The top-left cell is the starting point, and the bottom-right cell (marked with number 0) is the treasure location.
- Your function must calculate the number of unique paths from the start to the treasure following the rules of movement.
- If there is no valid path to the treasure, return 0.
- Bonus: Optimize the function for time efficiency.
Examples
Given the following 2D array:[[2,3,1],[1,1,1],[4,2,0]]Calling the function:decodeTreasureMap([[2,3,1],[1,1,1],[4,2,0]])Should return 2, as there are two unique paths to the treasure: right-down-right-down and down-right-right-down.
Links
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.
Duplicate Character Counter
Tue Aug 20 2024
Write a function named 'countDuplicateCharacters' that takes a single string as an input and returns a dictionary (or an object/map depending on the language) containing the counts of duplicate characters in that string. The function should be case-sensitive, meaning 'a' and 'A' should be counted as distinct characters. Characters that do not repeat should not be included in the result.