Given an NxM matrix of integers, find all paths from first cell to the last cell. You can only move down or to the right from the current cell (no backtracking). Also call out the time complexity of your solution and ways to optimise it further. E.g.
{1 2 3}
{4 5 6}
{7 8 9}Output should be:
1,2,3,6,9
1,2,5,6,9
1,2,5,8,9
1,4,5,6,9
1,4,5,8,9
1,4,7,8,9