The solution to this problem makes use of a technique known as depth-first search (DFS), which you will learn under the topic of graphs.
See http://www.cs.rochester.edu/u/kautz/Mazes/search/applet.html for an applet which shows how DFS finds a path through the maze.
What if we want to store three stacks in an array of n elements instead of two and still maintain the property that none of the stacks overflow unless the total number of elements in all three stacks is n?