Pingvin
InterviewTime limit1sMemory limit1024 MB
Find the fewest unit moves along the x, y, or z axis needed to fly from the start cell to the end cell through cloud-free cells in an n by n by n cube.
Pingvin
Zrakoplović the penguin wants to learn how to fly.
The space in which he will learn to fly is a cube of dimensions , divided into unit cubes. Each unit cube is described by three coordinates , where , and are integers between and . The coordinate is the distance from the left edge of the space, the coordinate is the distance from the front edge of the space, and the coordinate is the height.
Some of these unit cubes contain clouds, and some do not.
Zrakoplović is afraid of clouds, so he will fly only where there are no clouds. He starts at position , where (that is, at height ), and wants to reach position .
He is practicing flight in directions parallel to one of the axes (the -axis, -axis or -axis). In one wing flap he can cross at most one unit cube.
Before he flies, Zrakoplović wants to know how many wing flaps he needs to reach the destination. Help him find that number.
The start and end positions are never clouds.