God brought the various animals to the ark and God protected each species he created while on the ark
Perhaps ... but that answer sounds like a cop out. If the answer is God magically protected the animals he could have done that without an ark and all this trouble. He could have parted the waters. In fact God could have skipped the flood all together and just magically killed the humans via some virus that somehow spared the animals.
A more likely answer is the animals were placed in separate stalls in the ark by kind. That’s what I always assumed Noah did. A lot of work but building such an ark is a lot of work.