This is what I think the logic should be.
For compaction, we need to read and write every addressable unit once. How?
First consideration: Since it says random distribution and says ‘many’ holes and ‘many’ data. I am assuming equal number of holes and data segments.
So we can maintain 2 pointers, the first pointer will point to the hole from LHS and the second pointer will search for data from RHS to be swapped with this newly found hole. So by the time, we have found both the hole and data, we would have completed 2 READ operations. Similarly, we need swap to data and hole content, hence 2 writes. And this will happen for each memory address.
And hence we can say compaction time=(read time+write time) * number of addressable memory units
= (4+4) * $2^{30}$ ns
Please comment down if you think the solution is wrong.