there is no need to construct a whole graph just keep the trackYaron Wittenstein wrote:I want to solve this problem by building a graph and running

topological sort on it and then finding the longest path in the graph.

now for a dense graph I get E = V^2

where V <= 6 * 500 right? (6 positions and 500 cubes maximum)

so (6*500)^2 is too much space isn't? (for int array)

there is another option? (I guess they dont expect me to work

in bits level)

please help me here, or tell me another option for solving

this question.

for each node instead of

finding its children

find the nodes that can be its parent