There are actually two solutions:
First solution - You fill the three gallon bucket up, and pour that three gallon bucket into the five gallon bucket. The five gallon bucket now has 3 gallons of water in it. You then fill the three gallon bucket up again, and fill the five gallon bucket to the brim. Since you only had 2 gallons of space left in the five gallon bucket prior to pouring the second bucket in there, and you're pouring using a three gallon bucket, then that means you have 1 gallon left over in the three gallon bucket after this second pour. You pour that 1 gallon into the five gallon bucket, and then you fill the three gallon bucket up one more time and also pour that into the five gallon bucket. Since you already had 1 gallon in the bucket, and you pour the entire three gallon bucket in there, then you now have 4 gallons.
Second solution - You pour water into the five gallon bucket to the brim, and then pour that water into the three gallon bucket. Once the three gallon bucket is full, you will be left with 2 gallons in the five gallon bucket. Pour the three gallon bucket out, and then pour the 2 gallons from the five gallon bucket into the three gallon bucket. Now, fill up the five gallon bucket again. Since you only have 1 gallon of space left in the three gallon bucket since it's already holding 2 gallons, filling the three gallon bucket to the brim from the five gallon bucket will result in there being only 4 gallons in the five gallon bucket.