Problem · Array
Sort Documents Left to Right
Learn this problemProblem 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.