Finding patterns or sequences in data is not often needed, but when it is, the arsenal of solutions is fairly limited. Here is another tool for the toolkit
Nasty stuff, nested objects. Thing of multipart polygons, some parts have holes, some holes have parts with holes. How many at each level? You can recurse through the maze.