You have to think about what they are trying to test. If it's "Do they know how to quickly find an answer to a known problem?", then your route is correct.
If it's "Could they take a problem that hasn't been solved before and solve it themselves?", then you're not really demonstrating that.
Unless I'm told otherwise, I would assume that a coding challenge would be more of the latter.
Of course, it's not how you'd solve it in real life. But that's like saying you should be allowed a calculator in a mental maths exam because you'd never try to to 27324/623 in your head these days.