FastPrepRecover Document Hierarchy from Indentation
Problems/Recover Document Hierarchy from Indentation

Recover Document Hierarchy from Indentation

Reducto logoReducto● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report supplies border-distance objects, hundredth-level precision, and divide-by-base indentation, but omits field names, reading order, rounding guarantees, output serialization, and bounds. This deterministic layout transformation is an approximately 73% match.

A document parser returns text objects in reading order. texts[i] is the object's text, and distances[i] is [left, top, right, bottom], its distances from the four page borders.

The left distance encodes indentation. A positive baseUnit is one indentation level, and every quotient distances[i][0] / baseUnit is within 0.01 of one unique nonnegative integer.

Return one string per object, preserving reading order, in the form level|text. The level is that unique integer. The other three border distances do not affect it.

Function

recoverIndentation(texts: String[], distances: double[][], baseUnit: double) → String[]

Examples

Example 1

texts = ["Title","Section","Paragraph","Note"]distances = [[0,0,8,1],[2.01,1,5.99,1],[4,2,4,1],[6.02,3,1.98,1]]baseUnit = 2return = ["0|Title","1|Section","2|Paragraph","3|Note"]

Each left distance is within one hundredth of a multiple of 2, so the levels are 0 through 3.

Example 2

texts = ["Heading","Indented","Back"]distances = [[0,7,9,2],[2.49,0,1,3],[1.26,8,4,0]]baseUnit = 1.25return = ["0|Heading","2|Indented","1|Back"]

The levels follow left distance only and preserve input order; they do not need to be monotone.

Constraints

  • 1 <= texts.length == distances.length <= 100000.
  • Each text has length from 1 through 100.
  • Every distance row is [left, top, right, bottom].
  • All distances are finite values from 0 through 1000000 with at most two decimal places.
  • 0.01 <= baseUnit <= 1000000 and it has at most two decimal places.
  • Every left / baseUnit quotient is within 0.01 of one unique nonnegative integer no greater than 1000000.

More Reducto problems

  • Group Bounding Boxes by IndentationPHONE SCREEN · Seen Oct 2026
See Reducto hiring insights
Saved
class Solution {
    public String[] recoverIndentation(String[] texts, double[][] distances, double baseUnit) {
        // Write your solution here.
    }
}
Checking account…