Link at the correct address so there's 1MB between the end of the application image and the bottom of the stack. Allow the linker to load the shared libraries (or just link statically) and then use mmap to fill the rest of the virtual address space. You can implement this in multiple ways.
It's a bit of a weird exercise, you'd generally just calculate the maximum space used by the algorithm, maybe account for stack frame size if recursion is used.
It's a bit of a weird exercise, you'd generally just calculate the maximum space used by the algorithm, maybe account for stack frame size if recursion is used.