You are not allowed to use any extra space other than the internal stack space used due to recursion. You are not allowed to use the loop constructs of any sort available as handy. For example: for, for-each, while, etc. The only inbuilt stack methods allowed are: push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element.