Skip to main content
LeetCode 1457, Medium. Topics: Bit Manipulation, Tree, Depth-First Search, Breadth-First Search, Binary Tree. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 28 parametrized pytest cases, and a playground notebook:

Problem

Given a binary tree where node values are digits from 1 to 9 only. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of the node values in the path is a palindrome. Return the number of pseudo-palindromic paths going from the root node to leaf nodes.

Examples

Example 1
Example 2

Constraints

  • The number of nodes in the tree is in the range [1, 10^5]
  • 1 <= Node.val <= 9

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026