Sum of Odd-Positioned BST Nodes

viaGlassdoor

Problem: Given a Binary Search Tree, compute the sum of node values that fall at odd positions in a chosen traversal order (in-order or level-order), where position numbering starts at 1.

Constraints: Standard BST with up to N nodes.

Example: In-order sequence [1,2,3,4,5,6,7] -> odd positions are 1st,3rd,5th,7th -> sum = 1+3+5+7 = 16.

Approach: Traverse the tree (in-order recursively or level-order via BFS) while maintaining a running position counter; add node values found at odd positions to an accumulator. Time complexity O(n), space O(h) for recursion stack or O(n) for a BFS queue.

Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account