Sort Documents Left to Right
Updated
Problem statement
Each document is represented by [documentId, leftX], where leftX is its integer left-edge coordinate on a canvas.
Return the document identifiers ordered from left to right by increasing leftX. When two documents have the same coordinate, preserve their original input order.
Function
sortDocumentsLeftToRight(documents: String[][]) → String[]Examples
Example 1
documents = [["header","40"],["sidebar","10"],["card-a","25"],["card-b","25"]]return = ["sidebar","card-a","card-b","header"]The two cards share a coordinate, so their input order is preserved.
Constraints
1 <= documents.length <= 200000- Every row contains exactly two strings.
- Document identifiers are unique nonempty ASCII strings of at most 40 characters.
-10^9 <= leftX <= 10^9.
More Figma Onsite Interview questions
- Recursive Display SortPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 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
- Table Selection and Color UpdatesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Symmetric Binary TreeONSITE INTERVIEW · Seen Feb 2026
- Topmost Accessible NodesPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2025
- Nested Template Variable ExpansionONSITE INTERVIEW · Seen Jun 2024
- Parse, Validate, and Repair Markdown FormattingONSITE INTERVIEW · Seen Jun 2024
- Breadth-First Values of a Binary TreeONSITE INTERVIEW · Seen Oct 2022
Similar questions at other companies
- Group Transactions by HourAffirm · ONSITE INTERVIEWAffirm interview questions
- Merge Sorted ArrayDP World · ONSITE INTERVIEW
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Meeting RoomsGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Sort Products by Aisle With Frozen Items LastInstacart · ONSITE INTERVIEWInstacart interview questions
- Merge Two Arrays Into Sorted OrderNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Compress Consecutive Integer RangesDocuSign · ONSITE INTERVIEWDocuSign interview questions
- Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Rank Transform an ArrayAgoda · ONSITE INTERVIEWAgoda interview questions
- Filter and Sort Scheduled TasksRippling · ONSITE INTERVIEWRippling interview questions