The output happened to be right but the method to get there was fundamentally wrong and would be faulty if used in other scenarios.
Getting the right answer for the wrong reasons is still wrong in a way, the process to arrive at the conclusion is important.