Tap here to switch tabs
Problem
Submissions

Problem: Flatten Binary Tree to Linked List

Flatten Binary Tree to Linked List reshapes a binary tree in place so its nodes follow preorder, with every left pointer cleared and each right pointer leading to the next node.

Statement

Given the root of a binary tree, the task is to flatten the tree into a linked list using the same TreeNode class. The left child pointer of each node in the linked list should always be NULL, and the right child pointer should point to the next node in the linked list. The nodes in the linked list should be in the same order as that of the preorder traversal of the given binary tree.

Constraints:

  • −100≤-100 \leq Node.data ≤100\leq 100.
  • The tree contains nodes in the range [1,500][1, 500].
⋮
Tap here to switch tabs
Problem
Submissions

Problem: Flatten Binary Tree to Linked List

Flatten Binary Tree to Linked List reshapes a binary tree in place so its nodes follow preorder, with every left pointer cleared and each right pointer leading to the next node.

Statement

Given the root of a binary tree, the task is to flatten the tree into a linked list using the same TreeNode class. The left child pointer of each node in the linked list should always be NULL, and the right child pointer should point to the next node in the linked list. The nodes in the linked list should be in the same order as that of the preorder traversal of the given binary tree.

Constraints:

  • −100≤-100 \leq Node.data ≤100\leq 100.
  • The tree contains nodes in the range [1,500][1, 500].