Generationg heightmaps and aply them to terrain?

I have an algorithm that generates greyscale heightmaps. I need to khow how to after its generated aply it to the terrarin

You can import your hightmaps using the landscape tool. See picture

but during runtime how do i do it

Hi

There is no tool inside the editor that you can spawn a entire landscape in game. You will need to do it by script, but, you can create all landscapes and organize them to they appear or desapear during play when you want, it is called World Composition.

Check this documentation: World Composition User Guide | Unreal Engine Documentation

There are some videos in youtube about it too.