What happens if the miners cannot find the solution or takes a really long time. Because it looks like the solution not only depends on nonce but also on no. of txn/position. So what if the miners cannot find solution to let's say hash that requires 30s from any of the combination and nonce because nonce is 2^32 which can run out quite easily without finding a solution. What happens in such case or how does bitcoin prevent such situations?
There should always be a solution because there are more than 2
256 possible block headers for any particular block. There are many ways to change the block header than just varying the nonce, such as varying the time, the coinbase transaction, and the order of the transactions.
Sometimes blocks do take a long time, but that doesn't matter as it all averages out in the end to 10 minutes per block.