[Interview Experience] 6sense Coding Challenge — Org Chart & Unival Tree

In a recent 6sense technical interview, one of our CSOAHelp students faced two deeply conceptual problems — both centered around tree structures and recursive reasoning.
While neither question required heavy math or complex data structures, both demanded clean abstraction, structured logic, and clarity under time pressure.


🧩 Question 1: Build and Print an Organization Chart

Original Problem Statement

Emps
------------------------------------------------
ID | Name    | Manager ID
1  | Eric    | NULL
2  | Jack    | 1
3  | Viral   | 2
4  | Michael | 2
5  | Nitesh  | 1
6  | George  | 4
7  | Ryan    | 2

Emp ==> { id: int, name: string, mid: int }

Write a function which takes input as a list of Emp(s),
and prints out the org chart as follows:

Expected Output:

Eric
|__ Jack
    |__ Viral
    |__ Michael
        |__ George
    |__ Ryan
|__ Nitesh

💡 Thought Process

This question essentially tests hierarchical data modeling — transforming a flat employee table into a recursive tree structure.

During real-time CSOAHelp coaching, the candidate broke the problem into two logical phases:

  1. Tree Construction
    • Build a Map<ManagerID, List<Employees>> to represent manager-subordinate relationships.
    • Identify the root node (ManagerID == NULL), which in this case is “Eric”.
  2. Recursive Printing
    • Write a DFS-style function that prints each node with indentation.
    • Maintain proper prefix formatting (|__ ) for each level.

With instructor feedback, the candidate refined the recursion to ensure consistent spacing and line breaks — a subtle but critical detail that impresses interviewers in structured-output problems.


🌳 Question 2: Unival Tree

Original Problem Statement

A unival tree is an n-ary tree in which all nodes have the same value.

This is a valid unival tree:
   1
  / \
 1   1
/ \ / \
1  1 1 1

This is not:
   1
  / \
 1   2
 / \
1  1 2 1

This has 8 unival subtrees:
      1
     / \
    2   3
   / \ / \
  2  2 3  3
 / \ / \
5  5 4  4

Part 1: Validate if a given tree is a unival tree  
Part 2: Count the number of unival subtrees

🧠 Reasoning and Implementation

This problem targets two dimensions: boolean recursion and count aggregation.
The challenge lies in combining both within a clean recursive structure.

Under CSOAHelp’s real-time guidance, the candidate adopted a dual-return recursive approach — each function call returns:

  • Whether the current subtree is unival, and
  • How many unival subtrees exist within it.
def helper(node):
    if not node:
        return True, 0
    left_uni, left_count = helper(node.left)
    right_uni, right_count = helper(node.right)
    is_uni = left_uni and right_uni and \
             (not node.left or node.left.val == node.val) and \
             (not node.right or node.right.val == node.val)
    return is_uni, left_count + right_count + (1 if is_uni else 0)

This elegant approach merges validation and counting into one traversal, achieving O(n) time and O(h) space.

The CSOAHelp instructor emphasized how this solution demonstrates composable thinking — breaking a recursive problem into logical, reusable components.


💬 Interview Feedback

6sense interviewers were impressed with the clarity of reasoning and code readability.

“Your recursion structure was clean, and your explanation was precise.”

“We liked how you modeled hierarchy in the first problem and integrated logic and counting in the second.”

By articulating time and space complexity, and clearly walking through base and recursive cases, the candidate displayed both technical competence and communication maturity — two traits 6sense prioritizes.


🚀 Why CSOAHelp Makes a Difference

The turning point in this session wasn’t just about getting the code right — it was about developing the structured thinking that modern interviews demand.

With CSOAHelp’s real-time interview support, candidates gain:

  • 🧭 Step-by-step logical breakdowns under time pressure.
  • 💬 Instant feedback to refine recursion or data modeling.
  • 💡 Mock interviewer prompts to prepare for “what if” questions.
  • 🧠 A focus on clarity, not just correctness — because readable code wins interviews.

If you’re preparing for 6sense, Databricks, or FAANG-level system and recursion interviews,
don’t rely on blind LeetCode grinding.

Join CSOAHelp.com
where real engineers and interview experts guide you through problems like these,
helping you turn logic into confidence and performance into offers.

Leave a Reply

Your email address will not be published. Required fields are marked *