15% off all plans & roadmaps Use code
See plansLeetCode 1457 · Solution & editorial
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.
Pseudo-Palindromic Paths in a Binary Tree is a Backtracking Patterns problem, in the Palindrome Partitioning subpattern. The pattern covers subsets, permutations, combinations, N-Queens, and word search
Partition string into palindromic substrings using backtracking.
The reference solution runs in O(n) time and O(h) space.
Pseudo-Palindromic Paths in a Binary Tree has been reported in interviews at Amazon.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Pseudo-Palindromic Paths in a Binary Tree is a Backtracking Patterns problem, in the Palindrome Partitioning subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.