Line the bottom of a 9-inch spring form with parchment paper and grease the sides with butter. Preheat the oven to 350 degrees Fahrenheit.
Make the apple filling. Place the diced apples, sugar, lemon juice, and a splash of water in a large saucepan. Cook over medium heat for about 15 minutes, stirring occasionally, until the apples are soft. Some of the apples will break down while others will remain in small pieces — that’s exactly what you want. Remove from the heat, stir in the vanilla, and set aside to cool.
Make the dough. Add the flour, sugar, baking powder, and salt to a food processor and pulse briefly to combine. Add the cold butter, cut into pieces, and pulse until the mixture resembles coarse crumbs. Add the egg yolks and process just until the dough starts to come together. The dough will still be powdery - transfer to a large bowl of onto a clean counter and form a dough ball. You can also make it by hand in a bowl.
Chill the dough. Remove about ⅓ of the dough, wrap it, and place it in the freezer for at least 20 minutes. Press the remaining dough evenly into the bottom of a greased or parchment-lined 9-inch springform pan. Put the springform in the fridge while you prepare the meringue.
Make the meringue. Place the egg whites in a clean, dry mixing bowl and beat until stiff peaks form (about 7-10 mins). With the mixer running, add the sugar 1 tablespoon at a time, beating well after each addition. Continue whipping until the meringue is very thick, bright white, and glossy. Add the cornstarch or potato starch and mix briefly until incorporated.
Assemble the cake. Spread the cooled apple filling evenly over the dough. Spoon the meringue over the apples and spread it into an even layer. Remove the reserved dough from the freezer and grate it evenly over the top of the meringue using the large holes of a box grater.
Bake. Bake at 350°F for 45–50 minutes, until the grated dough on top is lightly golden. Let the szarlotka cool before removing it from the pan and slicing.