Heat oven to 180C/160C fan/gas 4. Grease a 20 x 23cm traybake tin with a little butter and line the base with a long strip of baking parchment that extends above the rim of the tin at either end – this will make it easier to get the slices out of the tin later.
To make the base, tip the flour, sugar and coconut into a bowl, mix everything together, then rub in the butter with your fingers to make coarse crumbs. Stir in the egg yolks with the blade of a knife, then bring the mixture together with your hands to make a dough. Press the dough into the base of the tin, smoothing it with the back of a spoon to make an even layer. Spread the jam over most of the dough, keeping it a little bit away from the sides of the tin.
To make the topping, whisk the egg whites with an electric hand whisk until stiff, then gradually add the sugar to make a glossy meringue. Fold in the desiccated coconut, then spoon over the jam layer. Scatter with the coconut flakes, if using, and bake for 25 mins until golden.
Leave to cool in the tin, then carefully lift out, using the parchment to help you, and cut into slices. Will keep in an airtight container for 2 days.