Hints — p81 Queue Reconstruction by Height
-
The k field counts taller-or-equal in front, not strictly taller. Same-height people count.
-
If you place the tallest person first, no one you place later can ever invalidate their k-count (shorter people don’t add to “taller-or-equal”).
-
Sort by
(-h, k)— tallest first, then ascending k among ties. Process in this order. -
When inserting person
(h, k): every already-placed person has height ≥ h. So the insertion index = count of taller-or-equal in front = k. Uselist.insert(k, [h, k]). -
Ascending k for ties matters: same-height persons count toward each other’s k, so place the one with smaller k first.
If stuck: see solution.py.