Challenge 📝
You are given a two-dimensional array arr
of integers, where each element in the array represents the cost of traveling from that cell to its adjacent cells. You start at the top-left corner of the array arr[0][0]
and you need to reach the bottom-right corner arr[m-1][n-1]
. Your task is to find the minimum cost of traveling from the top-left corner to the bottom-right corner.
You can only move down or right from a cell. You can assume that the input array is non-empty and that there is at least one valid path from the top-left corner to the bottom-right corner.
Examples:
const arr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
console.log(minimumCost(arr)); // 21
// path that the algorithm should find: 1 => 2 => 3 => 6 => 9 = 21