Pseudo-Palindromic Paths in a Binary Tree

Given a binary tree where node values are digits from 1 to 9. 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.

Example 1
        2
       / \
      3   1
     / \   \
    3   1   1
Inputroot = [2,3,1,3,1,null,1]
Output2
There are three root-to-leaf paths, and only [2,3,3] and [2,1,1] can be rearranged into palindromes.
Example 2
        2
       / \
      1   1
     / \
    1   3
         \
          1
Inputroot = [2,1,1,1,3,null,null,null,null,null,1]
Output1
There are three root-to-leaf paths, and only [2,1,1] can be rearranged into a palindrome.

Constraints

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

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate