The TransCompilator

Solved LeetCode program · 419 of 1,000

#0565 · Array Nesting

Medium Array chunk-09.md

Original English source

Keep a shared links holding 5, 4, 0, 3, 1, 6, and 2. The last is the last position of links. Keep a shared seen holding 0, 0, 0, 0, 0, 0, and 0. Keep a shared best of 0.
To walk from node (a whole number) with depth (a whole number). If item node of seen is 1, return. Set item node of seen to 1. If depth is more than best, set best to depth. Walk from item node of links with depth plus 1.

For every start from 0 to last.
Walk from start with 1.

Show best.

Open in Playground Browse all 1,000 problems

Expected stdout

4