There exist too-clever "gotcha" questions that are obvious if you've seen them before, and near impossible if you haven't. Those are terrible, and they fall to your "They're exams" criticism.
Other questions have layers, like an onion. Those are the good questions. They should divide the candidates into STRATA. I think the stock question is one of those.
Strata 1:
Everyone should be able to produce a brute-force, inefficient solution, and avoid the obvious+wrong solution. If not, they should have been weeded earlier by your phone screening.
Strata 2:
Better candidates should be able to produce a more efficient and readable solution, sometimes with prodding. Some candidates never get here, even with prodding ("Have you considered x,y,z?")
Strata 3:
Candidate skips straight to the correct solution, sometimes provides more than was required ("You shouldn't store data as keys; you probably want to return the time and buy/sell prices, not just the profit".) Interviewer needs to prod and ask questions here ("what's wrong with solution x? why did you do y? What if I want a list of possible trades?") to make sure it's not a memorized answer.
You shouldn't expect that, in ten minutes, your candidate can come up with the optimal solution that took you three hours. But they should be able to understand and recognize that solution if you lead them to it.
Anyone using these questions as pass/fail is doing it wrong, but that's not the question's fault.
Other questions have layers, like an onion. Those are the good questions. They should divide the candidates into STRATA. I think the stock question is one of those.
Strata 1: Everyone should be able to produce a brute-force, inefficient solution, and avoid the obvious+wrong solution. If not, they should have been weeded earlier by your phone screening.
Strata 2: Better candidates should be able to produce a more efficient and readable solution, sometimes with prodding. Some candidates never get here, even with prodding ("Have you considered x,y,z?")
Strata 3: Candidate skips straight to the correct solution, sometimes provides more than was required ("You shouldn't store data as keys; you probably want to return the time and buy/sell prices, not just the profit".) Interviewer needs to prod and ask questions here ("what's wrong with solution x? why did you do y? What if I want a list of possible trades?") to make sure it's not a memorized answer.
You shouldn't expect that, in ten minutes, your candidate can come up with the optimal solution that took you three hours. But they should be able to understand and recognize that solution if you lead them to it.
Anyone using these questions as pass/fail is doing it wrong, but that's not the question's fault.