Equal with some major caveats.
It is nearly impossible to determine how many calories you've burned during cardio without really expensive equipment attached to you. Your watch lies. Your heart monitor lies. Your gym machine lies. You are not burning the calories that you think you are burning. This could mean that it's very easy to over or under eat.
Another caveat, Person A may have more energy throughout the day so their NEAT may be higher. Thus they might end up burning equal or more calories in the long run over time.
Yet another caveat, Person A may have more energy to perform better in the gym thus lift heavier, thus build more muscle. If you do not practice progressive overload, then you do not build muscle. If you are not recovering, then you will have a difficult time practicing progressive overload. If Person B over-does the cardio, then they may not recover enough to perform in the gym.
Yet another caveat, Person A may have weaker cardiovascular abilities. This may mean that they have to cut their workouts short because they exhaust themselves sooner. If Person B can manage their recovery appropriately, then they will be able to outperform Person B in the long run.
What is "optimal" or building muscle and losing fat over the long run? Lifting weights while practicing progressive overload and doing a moderate amount of cardio if you have time. Just enough to ensure it doesn't interfere with lifting. This could mean a light active-recovery day on days you don't lift. It could mean more intense cardio after your lifting sessions.