Inorder Traversal

Binary Trees Theory/Traversals Easy

Given root of binary tree, return the Inorder traversal of the binary tree.

Examples:

Input : root = [1, 4, null, 4, 2]

Output : [4, 4, 2, 1]

Explanation :


Input : root = [1, null, 2, 3]

Output : [1, 3, 2]

Explanation :


Input : root = [5, 1, 2, 8, null, 4, 5, null, 6]

Constraints

  • 1 <= Number of Nodes <= 100
  • -100 Node.val <= 100

Hints

  • Since inorder traversal first visits the left subtree, we use a stack to store nodes while traversing left.
  • Push nodes onto the stack while moving left, process them, then move to their right child.

Company Tags

Broadcom ARM Seagate Technology Rockstar Games Freshworks Johnson & Johnson PayPal HashiCorp Medtronic Goldman Sachs Epic Games Flipkart Wayfair Snowflake Intel AMD Morgan Stanley Uber Airbnb Target Swiggy MongoDB Boston Consulting Group Reddit Bloomberg Google Microsoft Amazon Meta Apple Netflix Adobe