Flatten Binary Tree to Linked List

IF
AlgoAxiomStaff Engineers
JSTS
Medium20 mins

Given the root of a binary tree, flatten the tree into a linked list using the same TreeNode class where the right child pointer points to the next node and the left child pointer is always null.

Source: Tree Depth-First Search pattern — AlgoAxiom
JavaScript
Test Case 1
root = [1, 2, 3]
Test Case 2
root = [1, 2, 3, 4, 5]
Idle