Maintain a line of people with different heights who have preferences about the height of people ahead of them in line

An O(log N) solution to this problem. It uses a binary tree with an  insertion algorithm that helps ensure no one person's preference for how many people taller them can appear ahead of them in line gets violated. It assumes the input is sane and not presenting an un-solveable set of criteria.