This problem can be easily solved using a stack. My explanation of Tracing recursive methods explains the technique.
Also see my complete 2004 AP CS A Multiple Choice solutions.
2004 AP CS A Multiple Choice #26 Solution (as PDF)
This is an embedded Microsoft Office presentation, powered by Office Web Apps.
Copyright © 2022 mrHorn.com, Inc.
Brandon Horn - President
AP is a trademark of The College Board which was not involved with the production of, and does not endorse, this site.