That's basically what every white-boarding coding exercise is - pattern recognition based on computer science trivia. It's not illegal - every tech company does it.
You can look at white boarding as proxy IQ tests or aptitude tests, the latter of which are customized for the role in question. I'm on the fence when it comes to deciding which bucket white boarding falls into.
I see the parallel you’re drawing but in this instance it’s important not to. IQ is divisive precisely by being made synonymous to performance in every other task requiring abstraction.