Hand out N address ranges that don’t overlap. Ordering the starts (regions[0].base < regions[1].base < ...) looks like enough, but says nothing about where each range ends: a large region reaches straight into the next one.
Once the array is sorted by base_addr, each region only needs checking against its immediate predecessor. That’s the point of keeping it sorted: an all-pairs check becomes an adjacent-pairs check.
regions[i-1] only makes sense for i > 0, and a foreach index is unsigned: guard it with a real if/else, or index -1 wraps to the largest value instead of going negative.
Fix the class below.
Requirements
One working answer: brokenbench's own fix for this exercise. Try a few runs first.
What changes, against the code you started with:
docker run --pull always --rm -p 127.0.0.1:8787:8787 ghcr.io/adibis/brokenbench-runnerLooking for a runner on this computer…
The first start downloads about 250 MB; after that it starts in seconds and only downloads again when there's an update. Your code goes to the runner on your computer, not to chipdv.io.