HARDasked at 1 company

Count Paths That Can Form a Palindrome in a Tree

A hard-tier problem at 45% community acceptance, tagged with Dynamic Programming, Bit Manipulation, Tree. Reported in interviews at thoughtspot and 0 others.

Founder's read

You're given a tree and asked to count paths where characters can be rearranged into a palindrome. Thoughtspot has asked this. It's a hard problem, but the acceptance rate sits around 45%, which means it's solvable if you see the pattern. Most candidates freeze because they think about palindrome construction directly. The real trick is realizing that a string can form a palindrome if and only if at most one character has an odd frequency. That insight, combined with bitmasks to track parity, is what separates a solution from a blank screen. If you hit this live and go blank on the bitmask approach, StealthCoder surfaces the working path in seconds, invisible to the proctor.

Companies asking
1
Difficulty
HARD
Acceptance
45%

Companies that ask "Count Paths That Can Form a Palindrome in a Tree"

If this hits your live OA

Count Paths That Can Form a Palindrome in a Tree is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The key is to represent character frequencies as a bitmask, where each bit tracks whether a character appears an odd or even number of times. As you traverse the tree with DFS, you flip bits for each character you encounter. Two nodes with the same bitmask (or bitmasks that differ by exactly one bit) mean the path between them can form a palindrome. The trick most miss: precompute all bitmasks from root to each node, then count pairs efficiently. Bit manipulation makes this fast and elegant. Common failure point: candidates try to track actual frequencies and struggle with the counting logic. If you haven't drilled tree traversal with bitmasks before, this problem will test both your DFS confidence and bitwise thinking under pressure. That's where StealthCoder is your safety net on the live OA.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Count Paths That Can Form a Palindrome in a Tree recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Paths That Can Form a Palindrome in a Tree interview FAQ

Is this really asked at major companies or just Thoughtspot?+

Thoughtspot is the only company in the reported data for this problem. That said, the pattern, using bitmasks to track character parity in trees, appears across multiple companies' hard coding rounds. If Thoughtspot is interviewing you, this is a concrete risk.

What's the actual trick that makes this solvable?+

Bitmasks for character parity. Instead of tracking counts, use one bit per character to mark odd/even. A path forms a palindrome if at most one bit is set in the XOR of two nodes' masks. This collapses the problem into counting matching bitmasks, which is O(n) with a hash map.

How much harder is this than medium tree problems?+

Significantly. You need DFS, bitmask manipulation, and counting logic all at once. The 45% acceptance rate reflects that many candidates see the tree structure but miss the bitmask insight entirely. Medium tree problems usually isolate one concept; this chains three.

Do I need to memorize bitmask tree patterns to solve this?+

Not memorize, but recognize. If you've done a few problems with bitmasks (even not on trees), you'll spot it faster. The core idea, using bits to represent state and XOR for comparisons, is the skill. The tree part is just DFS.

What if I can't optimize the counting part?+

A brute force that checks all O(n^2) paths will time out. The optimization step (hashing bitmasks as you traverse, counting matches) is not optional. That's where candidates typically lose points or run out of time. Understand the hash map step cold before the assessment.

Want the actual problem statement? View "Count Paths That Can Form a Palindrome in a Tree" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.