The amount of stitches between color changes really depends on the size of the stitch. If you were using fingering weight yarn, you can have more stitches between than bulky, for example.
My first thought when I saw this hat is that it should be done intarsia, with one strand for each heart. That would add up to a lot of strands for a baby had, though.
If you do it stranded, you’d need to catch the carried yarn in the back of the work every few stitches on the bottoms of the hearts. I believe this site has video of a good technique to catch the yarn in back without having it show. If it doesn’t, I’ll try to explain, but it’s easier to see it than follow directions for it, I think.
As long as you catch the yarn, the strands across the back won’t be too long. You also have to be aware that dark hearts and a light background may allow the strands to show through.