FastPrepRecursive Display Sort
Problems/Recursive Display Sort

Recursive Display Sort

Figma logoFigma● HardFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes horizontal sorting, groups made by chains of vertical overlap, top-to-bottom order of groups, and recursive sorting of nested nodes. It does not give the node encoding or the exact tie rules. Our version is about 95% the same as the reported question.

You are given n display nodes through parallel arrays. Node i has identifier ids[i], parent index parents[i], horizontal coordinate x[i], and inclusive vertical interval [top[i], bottom[i]]. A parent index of -1 marks a root.

Sort each sibling list independently:

  1. Place siblings in the same group when their vertical intervals overlap directly or transitively.
  2. Order groups from top to bottom by their minimum top coordinate.
  3. Within a group, order nodes by increasing x, then increasing top, then original input index.

Return all identifiers in preorder: emit each sorted node, then recursively emit its sorted children. Apply the same sibling rule to the roots and to every child list.

Function

sortDisplayNodes(ids: String[], parents: int[], x: int[], top: int[], bottom: int[]) → String[]

Examples

Example 1

ids = ["A","B","C"]parents = [-1,-1,-1]x = [30,10,20]top = [0,5,30]bottom = [10,15,40]return = ["B","A","C"]

A and B overlap, so their group uses horizontal order B, A. The disjoint group containing C comes below it.

Example 2

ids = ["rootB","rootA","childR","childL"]parents = [-1,-1,1,1]x = [20,5,30,10]top = [0,0,10,12]bottom = [5,5,20,18]return = ["rootA","childL","childR","rootB"]

The roots overlap and sort by x. Preorder emits rootA, its horizontally sorted children, and then rootB.

Example 3

ids = ["A","B","C"]parents = [-1,-1,-1]x = [30,10,20]top = [0,3,7]bottom = [4,8,10]return = ["B","C","A"]

A overlaps B, and B overlaps C, so all three belong to one transitive group and sort by x.

Constraints

  • 1 <= n <= 100000, and all five arrays have length n.
  • Identifiers are unique non-empty strings of at most 50 characters.
  • Each parent is -1 or a valid node index, and the parent links form a forest.
  • -10^9 <= x[i], top[i], bottom[i] <= 10^9.
  • top[i] <= bottom[i].
  • Intervals that share an endpoint overlap.

More Figma Phone Screen questions

  • Route Graph Reachability with a Broken LinkPHONE SCREEN · Seen Oct 2026
  • Rich Text Parser Part 3 (Depth Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Rich Text Parser Part 2 (Parse Nested Groups)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Rich Text Parser Part 1 (Validate Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Layer History with Batch Undo and RedoOA · PHONE SCREEN · Seen Sep 2026
  • Table Selection and Color UpdatesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Topmost Accessible NodesPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2025
  • Intersection of Two RectanglesPHONE SCREEN · Seen Aug 2024
  • Sparse Canvas Paint HistoryPHONE SCREEN · Seen Sep 2023
  • Shell Path AutocompletePHONE SCREEN · ONSITE INTERVIEW · Seen May 2022

Similar questions at other companies

  • Subtree Access OverridesPinterest · PHONE SCREENPinterest interview questions
  • Tree-Dependent KnapsackGoogle · PHONE SCREENGoogle interview questions
  • Vertical Order Traversal of a Binary TreeBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Vertical Tree Traversal with Value TiesMeta · PHONE SCREENMeta interview questions
  • Vertical Order Traversal of a Binary TreeTokopedia · ONSITE INTERVIEWTokopedia interview questions
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Merge N-Ary Trees by KeyLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
  • Aggregate Machine TopologyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Deterministic Depth-First Graph TraversalWaymo · PHONE SCREENWaymo interview questions

Interview reports that mention this question

  • Figma interviews · November 2026

Figma interview experiences

  • Figma SWE Intern OA and Final Round: 21 Experiences
  • Figma SWE Intern OA Questions: 25 Experiences
All Figma interview questionsSee Figma hiring insights
Saved
class Solution {
    public String[] sortDisplayNodes(String[] ids, int[] parents, int[] x, int[] top, int[] bottom) {
        // Write your code here.
    }
}
Checking account…