Algorithm for ensuring that each element ends up in its specified range when composing a list I am designing a feature recommendation system and I have encountered an algorithmic problem and I am wondering if any of you know if there are known algorithms to solve this type of issue. In our recommendation system the content recommended can have in its metadata information at what range it should be put. To demonstrate: 


Items 1-2 can be put in slots 3-5
Items 3-4 can be put in slot 7-9
Item 5 can be put in slot 1
We are composing 9 element list which (based on content performance) may look like this: [5, 6, 2, 8, 1, 7, 3, 4, 9]


Implementation of this problem has a lot of corner cases (like ranges overlapping and content from 1 range takes the position from another range, thus making the whole result invalid). Do any of you know if there are some algorithms to handle this type of issue?

It would be best if the algorithm had time complexity lower than O(n^2)

Thanks a lot!
Here is my guess at your problem.

There are a bunch of items that you need to place in a vector.

Each item has a set of allowed positions in the vector.

You need to find an assignment of items to positions in the vector.

This is an instance of bipartite maximum matching. On one side you have the items, on the other you have the positions in the vector. You add an edge if the item can be put in the position. A maximum matching is one that puts each item in an allowed position, without collisions.