TCS Prime Software Engineer — Trees and BST Recursion Drill
- Field
- Engineering
- Company
- Tata Consultancy Services
- Role
- Prime Software Engineer
- Duration
- 20 min
- Difficulty
- Hard
- Completions
- New
- Updated
- 2026-06-09
What this round is about
- Topic focus. Two whiteboard problems, a binary-tree traversal and a binary search tree validation, both solved with recursion and then defended on complexity.
- Conversation dynamic. The panelist puts a problem on a card, lets you drive, and pushes on your base case, your return value, and your memory use rather than reading the statement to you.
- What gets tested. Whether you can state the base case, say what each recursive call returns, trace the tree by hand, and give an iterative alternative using a queue or a stack on demand.
- Round format. A live spoken session with a shared whiteboard where you draw the tree, number the visiting order, and dry-run your own code.
What strong answers look like
- Recursion stated first. You name the base case and what the call hands back to its parent before writing code, for example the height call returns the larger child height plus one.
- Complexity with the stack. You quote O of n time and then volunteer O of h space for the recursion stack without being asked.
- BST range insight. You validate a BST by carrying a valid range down the recursion, and you note that an inorder traversal of a valid BST is strictly increasing.
- Iterative on demand. When asked, you reach cleanly for a queue for level order or an explicit stack for inorder instead of freezing.
What weak answers look like (and how to avoid them)
- Local-only BST check. Comparing each node with just its immediate children accepts invalid trees, carry a min and max range down instead.
- Forgetting the stack. Saying O of n time but ignoring the O of h recursion memory, always account for the call stack.
- Silent coding. Writing in silence so the panel cannot follow you, narrate each step and each pop from the queue or stack.
- No base case. Jumping into the recursive step without the terminating case, state what stops the recursion before the rest.
Pre-interview checklist (2 minutes before you start)
- Recall the traversal templates. Have level order with a queue and inorder with a stack ready to write from memory.
- Have a sample tree. Be ready to draw a four to seven node tree to trace on the board.
- Identify the base case habit. Practise saying the terminating case first for any tree function.
- Think of the BST range trick. Rehearse validating a BST by passing a lower and upper bound down.
- Re-read the skewed-tree effect. Be ready to explain how O of h becomes O of n on a chain.
- Pull up complexity phrasing. Have the words for time and recursion-stack space ready for every solution.
How the AI behaves
- Probes every claim. If you say O of n it asks about memory, if you validate locally it hands you a tree that defeats the check.
- No mid-interview praise. It acknowledges the specific thing you said and pushes deeper, it will not say great answer.
- Interrupts on hand-waving. It stops you when complexity is vague or when you refuse to draw and asks you to be concrete.
- One question at a time. It asks a single thing, waits, and follows up before moving to the next problem.
Common traps in this type of round
- Range-free validation. Checking only node against immediate children and missing a deep ordering violation.
- Stack-cost omission. Quoting time complexity while ignoring the recursion stack of O of h.
- Iterative freeze. Going blank when asked to remove recursion instead of reaching for a queue or a stack.
- Two-children deletion slip. Mishandling the inorder-successor replacement when deleting a BST node with two children.
- Reciting without tracing. Stating a traversal name but being unable to number the visiting order on the drawn tree.
- Skipping clarification. Coding before asking whether the tree is empty, balanced, or has unique values.
Sample problems you'll face
The 2 problems below are the same ones you'll work through in the live session — no surprises. Read the constraints carefully; the AI persona will refer you to the on-canvas card by problem number.
- 1Level-Order Traversal of a Binary Tree
Given the root of a binary tree, return its node values level by level, from the root level down to the deepest level, with each level as its own group from left to right. Then explain your recursion base case, give the time and space complexity including the recursion stack, and be ready to produce an iterative version on request.
Example inputTree: 1\n / \\\n 2 3\n / \\ \\\n 4 5 6Example output[[1], [2, 3], [4, 5, 6]]- The tree may be empty (root is null); return an empty list in that case.
- Node values fit in a 32-bit integer; the tree has at most 10^4 nodes.
- State both the recursive and the iterative (queue-based BFS) approach and their complexity.
- Draw the tree on the whiteboard and number the nodes in the order they are visited.
- 2Validate a Binary Search Tree
Given the root of a binary tree, determine whether it is a valid binary search tree, where every node's value is greater than all values in its left subtree and less than all values in its right subtree. A check that only compares each node with its immediate children is not sufficient. Explain what each recursive call returns and the complexity including the recursion-stack space.
Example inputTree: 10\n / \\\n 5 15\n / \\\n 6 20Example outputfalse (node 6 is in the right subtree of 10 but is less than 10, so the BST property is violated)- Values may be treated as unique; decide and state how you would handle duplicates.
- An empty tree and a single node are both valid BSTs.
- Carry a valid min-max range down the recursion, or use the fact that an inorder traversal of a valid BST is strictly increasing.
- On the whiteboard, draw a tree that passes a naive parent-child check but is not a valid BST, and trace your code on it.
Interview framework
You will be scored on these 6 dimensions. The full rubric with definitions is below.
What we evaluate
Your final scorecard breaks down across these dimensions. The full rubric and tier criteria are revealed inside the interview itself.
- Recursion Base Case and Return Formulation20%
- BST Range Validation Insight20%
- Time and Recursion-Stack Complexity18%
- Iterative Traversal Conversion15%
- Whiteboard Trace Fidelity15%
- Input Clarification and Edge Handling12%
Common questions
Sources this interview is built on
Real candidate-report URLs (Glassdoor / AmbitionBox / PrepInsta / GeeksforGeeks / Medium) reviewed when authoring the questions, persona, and rubric. Verify the realism yourself.
- Level Order Traversal (Breadth First Search) of Binary Tree - GeeksforGeeksgeeksforgeeks.org
- Calculate the Diameter of a Binary Tree - takeUforwardtakeuforward.org
- Check if a Binary Tree is BST or not - GeeksforGeeksgeeksforgeeks.org
- TCS Interview Experience | Prime(2024) - GeeksforGeeksgeeksforgeeks.org
- Iterative Inorder Traversal of Binary Tree - takeUforwardtakeuforward.org
- TCS Interview Process 2026: Complete Guide (NQT + All Rounds) | ClearRound.aiclearround.ai