Dsa
Recursion
Easy
Inverted Tree Paths
Given a binary tree, return all root-to-leaf paths where the values in the path are in increasing order. The tree's nodes contain integers. A path is defined as a sequence of nodes connected by edges, starting from the root and ending at a leaf. A leaf is a node with no children.
Input Format:
- The first line contains an integer `n`, the number of nodes in the tree.
- The following `n` lines each contain an integer `v`, the value of that node, followed by two integers `l` and `r`, the indices of the left and right children respectively (0-based, with -1 indicating no child).
Output Format:
- Print each valid path in increasing order, with nodes separated by spaces.
Example:
Input:
5
3 1 2
1 -1 -1
2 -1 -1
5 3 4
4 -1 -1
Output:
3 5
Key concepts
recursiontreesbacktracking
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now