Apparently I've been living under a rock because despite 20+ years of professional software development (and a degree in discrete mathematics) I wasn't familiar or at least didn't recall this "invert a binary tree" problem. I had to look up what we mean by "invert" here.
My first thought was "flatten the tree depth first and then reverse that linear list" which I knew to be inefficient, but I'm guessing I'd eventually stumble upon the recursive version of that when I got down to the nitty-gritty.
But now that I think about it can't you solve this problem with a single boolean flag that says "read right to left" or "read left to right"? I.e,. if the children are labeled `A` and `B` and you interpret "normal" as A,B and "inverted" as "B,A", isn't that sufficient? That's basically what the recursive version of this algorithm is doing, but why bother to actually move data around?
I get that this is an abstract problem, but I'm having trouble understanding any practical use case for this concept.
If you've got a real, in-memory, linked-list-style binary tree my `is_inverted` flag seems like it would be sufficient.
And if the real problem is moving blocks of data around on disk or in buffers, then isn't this all a question of the exact "flat" representation of this tree?
If my whiteboard answer was "keep a flag that says whether or not the tree is inverted" would I be hired?
Can someone reframe this question in a way that makes it clear that the trivial rtl-mode vs ltr-mode is insufficient? The only way this question makes sense to me is if you're really looking for someone to come up with the serialized representation of that data structure that makes this transform efficient, but none of the public answers to this question seem to cover that at all.
I honestly don't understand how this problem is meaningful for the in-memory, linked-list case.