fill rebuilt the array as array[:start] + fill + array[end:]. When start came after end those two slices overlapped, duplicating the shared elements and growing the array while writing no value. Normalize start and end into [0, length] and fill in place with an index loop so an empty span is a no-op and the length stays fixed.