Intuition
The traversal part of this problem should be fairly obvious. A DFS traversal will take us through all root-to-leaf paths. Of course we need to save information about each path to evaluate if it is pseudo palindromic or not, but what is the least amount of information we can store?
One way is to store every value in the path is a string, and then evaluate if its pseudo palindromic at the leaf node. A pseudo-palindromic frequency map will have at most one odd count.
path = '11112'
freq = {
1: 4,
2: 1,
}
#there is only one odd count, so a palindrome can be made: 11211
The issue with this approach is that storing the entire path will consume lots of memory, and since the problem indicates that node values can only be in the range 1-9, we can keep a list of length 9 to continuously update the frequency of the path.
But we can do even better than that. Why must we store the entire count when all that is relevant to the problem is if the count is even or odd? We can just increment by one if the current count is zero or decrement by one if the current count is 1! In this way, we can store even less information.
path = '1111111111111111222'
freq = [0,0,0,0,0,0,0,1,0]
#even more memory efficient
But its possible to do even better than this! At this point we are only storing binary information in the list, so its possible to just keep all of this information in a bit and use bitwise operations to determine if the path is pseudo-palindromic! How?