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.
Strict IQ tests will select for a certain subset of the population, that's usually divided by socio-economic lines which highly correlate with race. That's not to say that certain races have intelligence correlations, but that IQ tests test for knowledge that is diffused along socio-economic lines.
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.
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.