FastPrepBuild and Render an Organization Role Tree
Problems/Build and Render an Organization Role Tree

Build and Render an Organization Role Tree

Stripe logoStripe● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Stripe intern online assessment. The source keeps an organization-role tree built in steps, and the goal of printing it. It does not give the operations, the order of the walk, the rules for changes, the input, the output or the limits. Our version is about 48% the same as the reported question.

Build a company’s role tree from relations given in any order, then return its text representation.

Each relation has the form role,parent. Exactly one relation has an empty parent and defines the root. Every other parent names another role in the input.

Visit each role before its children. Visit each child’s entire subtree before moving to the next child, using the sorted child order described below. Write each role as:

<two hyphens repeated depth times><role>

The root has depth 0. Sort every role's direct children in ascending lexicographic order before traversal.

Function

renderOrganization(relations: String[]) → String[]

Examples

Example 1

relations = ["engineer,manager","ceo,","manager,ceo","designer,manager","finance,ceo"]return = ["ceo","--finance","--manager","----designer","----engineer"]

The root's children are sorted as finance then manager. The manager's children are sorted as designer then engineer.

Example 2

relations = ["intern,engineer","engineer,lead","lead,"]return = ["lead","--engineer","----intern"]

The unordered relations form one chain with depths 0, 1, and 2.

Constraints

  • 1 <= relations.length <= 10^5.
  • Every role is unique and contains lowercase English letters, digits, or underscores.
  • Exactly one role has an empty parent.
  • Every nonroot parent exists, and the relations form one valid tree.
  • Relations may arrive in any order.

More Stripe Online Assessment questions

  • Split Tender Part 4 - RefundsOA · PHONE SCREEN · Seen Nov 2026
  • Split Tender Part 3 - SurchargesOA · Seen Nov 2026
  • Split Tender Part 2 - Expiration DatesOA · Seen Nov 2026
  • Split Tender Part 1 - Basic Split TenderingOA · Seen Nov 2026
  • Asynchronous Event ProcessingOA · Seen Nov 2026
  • Subscription and Usage-Based Billing CalculatorOA · Seen Nov 2026
  • Payment Partner RoutingOA · Seen Nov 2026
  • Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
  • Maximum Game Score with Fixed Forward JumpsOA · Seen Nov 2026
  • Reliable LLM Call with Independent Retry BudgetsOA · Seen Nov 2026

Similar questions at other companies

  • JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
  • Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
  • Count Distinct Rooted-Tree GraftsThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Merge Row Trees by Key PathHudson River Trading · OAHudson River Trading interview questions
  • Get Most Hydrated TeamAirtable · OAAirtable interview questions
  • Resolve Inherited Server ConfigurationIntuit · OAIntuit interview questions
  • Palindromic Paths to the RootRippling · OARippling interview questions
  • Find PalindromesGoogle · OAGoogle interview questions
  • Validate BST Node DescriptionsAirbnb · OAAirbnb interview questions
  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions

Interview reports that mention this question

  • Stripe OA: What It Tests (2026)
  • Stripe SWE Intern Org-Tree OA: 1 Experience

Stripe interview experiences

  • Stripe New Grad SWE OA and Phone Screen: 2 Experiences
  • Stripe Experienced SWE OA and Onsite Questions: 3 Experiences
  • Stripe SWE Intern Linked Merchants Team Screen: 1 Experience
  • Stripe SWE Onsite over Two Days: 1 Experience
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    public String[] renderOrganization(String[] relations) {
        // write your code here
    }

}
Checking account…