I have a structure like this:
[
{index: 1, children: [2]},
{index: 2, children: [3, 4]}
{index: 3, children: [4]}
{index: 4, children: []}
]
and I wanna find all possible paths in this structure so I eventually get the longest one (I need to decide the max length of the whole trip). So in this structure the algorithm should export something like
[[1, 2, 3, 4], [1, 2, 4]]
or just the final answer which is 4 (the length of the longest trip). I found a few solutions online, at this point I am sure that this is only solvable with recursion but just can't figure it out. Any ideas of implementing this would be awesome, I am trying to solve this with js.