Your algorithm was correct, your code was correct, but you still got rejected. This is not only possible, but incredibly common.
Candidates are routinely surprised when it does because they don’t quite understand the interview process and how they are evaluated.
Read more