Here's our original solution which is recursive. Try converting it to iterative code, where the function doesn't call itself.
To solve this, we want to create our own Call Stack, which just means storing a stack
which contains all the inputs that we want to run treesEqual
on.
We could solve this problem by visiting every input twice, but it's actually easier to just return False immediately if we see any trees that are not equal, and return True at the end otherwise.
Time Complexity O(n)
Space Complexity O(n). The stack grows in the same exact way as the recursive solution, so it has the same space complexity.