Hello, I have a 2D square matrix that looks something like this for example:
const exampleGridB = [
[9, 32, 12, 14],
[21, 20, 3, 0],
[4, 0, 1, 2],
[0, 5, 13, 1]
];
The idea is that you have to find several paths and return the largest sum along with the path used, following this rule:
You can only move diagonally one square up or one square down and only start from the first column but you can choose the row (by moving diagonally one square up/down you can only move like in examples below but you cannot do something like: 9, 0 , 5 so you cannot skip that far so it s a bit like chess).
In other words you can have paths like this:
9, 20, 1, 1
21, 0, 13
4, 5
or something like this (zig zag or check mark)
9, 20, 12, 0
9, 20, 1, 0
21, 0, 13, 2
Can anyone help with an idea is there an algorithm that can be applied for this case?
It looks like a recursion should be involved.
Any idea is welcome.