We are talking about two myths. Giants and the flood.
The basis for the flood legned is differcult to ppintpoint by likely originated as oral stories around the black sea. Around 8000-6000BCE at the end of the last ice age as the ice melted flooding occured in what had been lowlands. These stories were passed down until a story was written down around 2200 BCE which later because a Babylonian Epic of Gilgamesh.
Jews in the exile were exposed to these stories and remember after the return in the 6th and 5th centuries carried it with them.
I used to think the flood story (J) was written in the exile however the evidence is the book og Genesis was unknown or quoted by anyone until after 200BCE. in the Hellenistic period.
Berosos a Babylonian hostorian writing in the 280s wrote history of Babylonian in Greek. Included in it was the Flood story from the Epic. (along with many other stories.
The Greek Septuigent in the FIRST record we have of biblical history** It was 'translated' in the 270s or 260s... I think the Jews created and Epic. and used Berosos.
The Giant legends are less easy. However given this is in the same book as the flood these are likely Jewish version of Hellenistic legend such as Cyclos etc. Indeed Genesis ^:1 sounds like the gods coming to earth.
** There is a small piece of Numbers 6 discovered from around 600BCE before the exile but it is a simple priestly blessing and was only a ritual prayer... these lines are not proof of a Torah.