The key point in building the coequalizer is to figure out the $"\sim"$ equivalence relation. This simply mean that we need to somehow partition the set Y.
Note that the smallest the equivalence relation, the largest the number of partitions. Thus, our goal is to partition Y as far as possible under certain conditions.
The largest number of partitions happens when we put each element of Y into one partition. However, we need to merge some of these partitions to satisfy the coequalizer definition. To this end, I think following the following pseudo code will will provide us with the desired partions:
$P = empty // keep the partitions for each $y in Y{ build a new partition called $p; put $y in $p; put $p in $P; } for each $x in X { merge the partitions in $P that contain either f(x) or g(x); }
The above pseudo code build your partitions in Y. This might be the one that you can get with the smallest equivalence relation with the conditions explained for the coequalizer.