MediumCategory: Trees / DFSAcceptance: 68%
Write an optimal implementation to solve the **lowest common ancestor binary tree** challenge for Data Structures & Algorithms.
Ensure your solution handles edge cases, executes with efficient time complexity, and passes all automated test cases.
Input: input = [1, 2, 3]
Output: [3, 2, 1]
Explanation: Example transformation for lowest common ancestor binary tree.
- 1 <= input.length <= 10^5
- Time complexity must be O(N) or better.
- Space complexity must be O(1) auxiliary space where applicable.