Farming pumpkins and melons in Minecraft is not very hard, but there are a few tips and tricks which make pumpkin and melon farming easier and a lot more efficient. There are two methods which you are able to increase your yield and efficiency, one is by using a set up that allows for the most pumpkins and melons to spawn in the shortest time, while the other will allow the most pumpkins and melons to spawn on as little land as possible.
Apparently, melons and pumpkins do not grow on the block you planted it. Instead, they will spawn on any available grass or dirt block next to the fully grown pumpkin or melon stalk. It means you have to leave some space between every row of seeds you plant or else nothing will grow. Please take a note that 1 pumpkin or melon block is able to spawn each melon or pumpkin stalk, but more than 1 stalk is able to attach itself to a single pumpkin.
If a pumpkin or melon stalk spawn a pumpkin or melon, each other stalks of the same kind next to that pumpkin or melon will attach itself to it, meaning it will not grow another melon or pumpkin until you destroy the one it is attached to.
Time efficient farming is all about obtaining as many pumpkins or melons in a short time, which is not hard to set up, but it does need a lot of player input on a regular basis. As you probably know, a pumpkin or melon is able to spawn on each block next to one of their stalks, as long as it is empty. It means they are able to spawn in up to 4 blocks per stalk. You can use this to your benefit, as pumpkins and melons will spawn a lot faster when more spaces are available to them to spawn in.
The field will be a simple rectangle in which you plant rows of seeds, however, you leave a space between every seed in order to make sure you maximize the spaces in which pumpkins are able to spawn. Keep in mind that you only leave 1 space between each seed instead of 2, it will decrease the size of your farm, but it does mean 1 pumpkin will attach itself to 2 stalks.
It is not impossible to leave 2 spaces between every seed you plant, but you are going to harvest the melons and pumpkins as fast as possible, meaning you do not really need that extra space and it makes your field a little too big, especially if you have to run one side to the other in order to get a melon.
You also know a single block of water will hydrate all farmland up to 3 blocks away from it, including diagonally. It means you are able to simply plant your seeds around that water block. You will have to sacrifice 1 potential spawn spot for that water block, but this is clearly worth it.