InterviewLegend

Trees & BSTs

Alex Chen30 min readUpdated 330 real interview reports

Trees show up across SAP's interviews, usually at an easy to modest level. One SAP Concur software engineer had virtual technical rounds with a BST problem, a leaf count and a question about the nodes larger than a given leaf, and the advice they passed on afterwards was to brush up on trees. An SAP Labs Developer Associate round asked for plain BST search.

Rebuilding a tree from its preorder and inorder traversals is the toughest of these. A Java Developer Associate candidate got it in a first face-to-face technical round, between questions on OOP and Java threads, and walked through a brute force before the optimal build. In all three, say one thing out loud before you start coding. On the BST walk, explain why one comparison rules out a whole subtree, and on the leaf count, say what an empty tree returns. The rebuild needs a short explanation of why slicing arrays on every call drifts back to O(n²) on a skewed tree.

Settle the edges of the input before the recursion. An empty tree, a lone root, a target that is its own ancestor, and duplicate values that make two traversals ambiguous each change what the code returns. Each one takes a sentence to settle. SAP's tree rounds reward clarifying questions asked early, and getting these cases right decides whether the hidden tests pass.

SAPPremium lesson · Coding round

The 3 SAP problems are below.

  1. A Premium questionCoding · Medium
  2. A Premium questionCoding · Easy
  3. A Premium questionCoding · Medium

Each with hints, the follow-up and a tested solution.

Get the SAP questions

$49 a year · all 100 companies · cancel anytime

From 330 SAP reports, forum threads behind logins and write-ups in Chinese.

Had your SAP interview?Tell us what they asked. Reviewed before it goes in, never with your name.
SAP interview guide

Know what SAP asks before you walk in.

25 coding · 2 system design · 30 behavioral questions

Get Premium$49 a year · Cancel anytime
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.