
… contract (perhaps the prize for this solution is in the millions, and hence many are watching it), they can scan the network and check when someone submits a valid solution. Once they see this tx in the mempool, they can take the solution, and resubmit it with their own address with a higher gas price, and if they manage to get their tx in before you, they’ll have stolen your prize!
Of course, another scenario is the miners themselves stealing your prize. In that case, they don’t even have to play the gas price game, they can simply choose not to include your tx in their block, and place their own in with the solution.