I would favor the one that answers the question over the one that provides an alternative, possibly better solution. In these situations the alternative may even get (a whole lot) upvotes and even comments saying "the other answer should have been accepted".
I would upvote the alternatives since they are also correct in that they solve the problem, but I prefer to see answers that actually answer the question, rather than an answer that solves the general problem behind the question.
Maybe someone that has the same problem would come across the question and then read the answers and realize that they probably shouldn't be trying to approach the problem the way they thought, or maybe they'll learn something new and use the alternative, possibly better solution.
For example, I'm looking to do something using regex, and someone presents a solution using a built-in function.
Maybe my regex approach was bad (aesthetically unappealing, error-prone, etc).
Maybe I'm just doing it using regex as an exercise.
Maybe, based on poor design decisions, I've been forced into a situation where I need to use regex and re-designing the entire thing may be unfeasible within the given constraints (eg: deadline in 72 hours)
On the other hand, if the question was presented as an XY problem, then it would likely be more attractive to pick the alternative solution that addresses the actual problem, rather than whatever problem the askers have created for themselves. But then to me that doesn't really answer the question although I'd consider it a bad question in hindsight.
Justifications could be made for either side. I tend to think that while someone may be faced with an XY problem, for someone else it might not be an XY problem, and for some it is for instructional purpose.