Any method that allows you to make a comparison either indirectly (or directly) with the boxes will work. Ordering the boxes is the easiest but as long as you can extrapolate the information from any kind of organization of the boxes (if we assume that they don't have labels, have been arranged in random order, and don't have any link between the two sets) will do.
The theoretical way of understanding this is through that of a relation in mathematics.
You just need some way to be able to relate the two boxes with rocks to each other and for your purposes, you need to do it with regard to what the box corresponds to numerically.
Think of it like a chain: you have two ends of the chain but as long as the whole thing is linked so that there is a "path" for a way to relate the two boxes in terms of which is bigger then it doesn't matter how much depth there is in the organization of the boxes and their relationships (i.e. how deep the chain is): the only thing is that a relationship exists to discern the answer.
You could create many many ways of organizing the boxes and force constraints to know how to get particular attributes, and ordering the boxes in consecutive order is definitely one way to do it: but there are many ways.