Truly brilliant code. I came up with the sorting part but did not came up with this collecting method with a list. Here is my verbose version just for reference: after sorting, I build the linked list (not the built-in linked list type) from ground up.

public class Solution { public int[][] reconstructQueue(int[][] people) { if (people.length == 0) return new int[0][2]; Arrays.sort(people, new Comparator<int[]>() { @Override public int compare(int[] a, int[] b) { if (a[0] != b[0]) return b[0] - a[0]; else return a[1] - b[1]; } }); Node res = new Node(people[0]); for (int i = 1; i < people.length; i++) res = insert(res, people[i]); int[][] resAr = new int[people.length][2]; for (int i = 0; i < people.length; i++, res = res.next) resAr[i] = res.person; return resAr; } public Node insert(Node node, int[] person) { Node newNode = new Node(person); int rank = person[1], height = person[0]; if (rank == 0) { newNode.next = node; return newNode; } Node curr = node; while (rank > 1) { curr = curr.next; rank--; } Node next = curr.next; newNode.next = next; curr.next = newNode; return node; } public static class Node { int[] person; Node next; public Node(int[] p) { person = p; } } }Queue Reconstruction by Height