If they have written it they should be able to discuss it and answer questions easily.
If someone else wrote it and they have understood it enough to discuss it, you probably have an even better developer, especially if the job involves working with some legacy code.
That can be really difficult for a lot of candidates. It's predicated on the idea that they've written code they:
a) Feel comfortable sharing (not just a one-off weekend hack project)
b) Are allowed to share, legally. This is usually the real problem for most developers.
The truth about hiring: There really isn't any one-size-fits-all that works for everyone. Any hiring process you come up with is going to be an incredible obstacle for a sizable minority of people.
If you base your hiring decision on how awesome they are at leetcode hackerrank style algorithm questions you're selecting for bullshit artists who memorized "cracking the coding interview".
There's a systematic industry-wide bias against realism in developer tests. It's depressing how many people think realism either isn't necessary or isn't possible within typical interview time constraints.