43. Binary Tree Inorder Traversal

43. Binary Tree Inorder Traversal

Easy
67.0%
2.3k
dfstreebinary-treestackrecursion
Google, Amazon, Netflix, Meta (Facebook), Apple, Microsoft, Uber, Bloomberg, Airbnb, Stripe, Adobe, Salesforce, LinkedIn, Oracle

You’re interviewing for a backend or data engineering role at a FAANG-level company. The interviewer describes a real product scenario:

A large-scale analytics or recommendation platform stores hierarchical data such as category trees, feature flags, or dependency graphs using binary trees. For reporting, validation, or indexing purposes, the platform often needs to traverse the tree in a specific order.

One of the most commonly used traversal strategies is inorder traversal, where the system processes:

  • the left subtree
  • the current node
  • the right subtree

This traversal is especially useful when working with Binary Search Trees, as it produces values in sorted order.

This is a common practice coding problem for DSA question might ask in Google, Amazon, Netflix, Meta, Apple, Microsoft, Uber, and Bloomberg interviews.

Your Task

Given the root of a binary tree, return the inorder traversal of its node values.

Inorder traversal follows this order:

Left → Root → Right

Input Format

  • root: the root node of a binary tree

Each node is defined as:

TreeNode { int val; TreeNode left; TreeNode right; }

Output Format

  • A list of integers representing the inorder traversal of the tree

Examples

Example 1:

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

Example 2:

Input: root = []
Output: []

Example 3:

Input: root = [1]
Output: [1]

Constraints

  • 0 <= number of nodes <= 100
  • -100 <= Node.val <= 100

Loading editor...

[1,null,2,3]
[1,3,2]

Console Output

Click "Run Code" or "Submit" to see results

Your code will be evaluated by AI with instant feedback