Because it separates out those who went to Uni from those who learned to code in their basements.
More interestingly, some of the problems on places like hackerrank, which are expressed as math problems have fundamental problems in that the answers they posit as being correct are not. I dealt with one such failure, where one could write down an closed form solution for a problem in complex analysis that the author mistakenly assumed was a number theory problem. They did not comprehend that their answer was nonsensical.
Compare that poor souls experience with Elon Musk's interview question for a tech hiring position, "So, tell me about a time you had a really hard technical problem to solve and how you did it?" The difference is night and day.