The Good Doctor boss breaks down the finale's tragic and romantic twists

Warning: This article contains spoilers from the season 3 finale of The Good Doctor, "I Love You."

Love was lost and found on The Good Doctor.

Picking up where last week's episode left off, part 2 of the season 3 finale began with Dr. Claire Brown (Antonia Thomas) rushing Dr. Neil Melendez (Nicholas Gonzalez) back to the hospital to find out why he vomited and collapsed at the brewery. Claire and Dr. Lim (Christina Chang) hoped surgery would fix his injuries, but it couldn't because the internal damage caused septic shock, which couldn't be reversed. At least Melendez got a chance to say goodbye to Claire, Lim, and Dr. Glassman (Richard Schiff) before dying. And thus ended Gonzalez's final episode as a series regular on the ABC drama.

For showrunner David Shore, Melendez's tragic fate was decided from the moment the writers chose to injure him in the earthquake that kicked off the finale.

"I can tell you it was a really, really difficult choice," Shore tells EW. "But I’ve always felt in running shows that it can’t just be, 'Oh my God, is he going to die?! No he’s not.' I think in a medical show in particular, you have to set up situations where people might die regularly, guest cast and your regulars. Every now and again you have to be true to that, or else the stakes lose their stakes even in the other stories. Dramatically, that is what a medical show is all about. It’s all about the risk of losing somebody and what you’re willing to do in those circumstances."

Shores continues: "I just thought it was important that we take one of the people we truly care about and deal with that, and that was the lion’s share of what went into that choice. I recognize that we’re paying a big price by doing this. I recognize that we’re losing something very important to the show, but I’m hoping on a storytelling long-term, it’ll keep us going."

What makes Melendez's death even more unfortunate is that not only had Claire just realized she had feelings for him a couple episodes earlier, but she's also experienced so much loss this season. Thanks to Claire's friendship with Melendez, though, there's hope she'll handle this better than she did her mother's death.

Darko Sikman/ABC

"We’ve thrown a lot of crap at that poor character," Shore says. "I think, ironically, to a great extent because of Melendez and because of his guidance — and we see this in part 2 a little bit — she’s a bit of a different person now than she was when her mother died. The irony is that when her mother died, she lost a very unstable influence on her life. Now she’s losing a very stable influence on her life, which is a higher cost to pay, but she’s also been the beneficiary of that stable source."

The season 3 finale wasn't completely depressing, though, because it ended with Shaun (Freddie Highmore) and Lea (Paige Spara) finally getting together. With the help of a walkie-talkie, Lea listened while Shaun fought to save his patient Vera's life as water filled the sub-basement where she was trapped. This ultimately helped Lea realize she was wrong to reject him before and actually did love him. When Shaun and Vera eventually made it out, Lea kissed Shaun passionately and professed her love, which is where the writers hoped the season would end when they started working on it last year.

"We explored a bunch of different choices as things went along," Shore says. "I really liked his relationship with Carly, we all did. Jasika Nicole was so great. But Paige is so great and Lea's so great, and this felt right at the beginning and right at the end. It feels like this is where it should be, and we'll explore that relationship next year as well."

Shore is proud of the way they brought Shaun and Lea is together because they avoided having Shaun simply save Lea's life. "We had Shaun prove, and more accurate remind her who he is, which reminded her or informs her — not that she owes him anything or anything along those lines — that when she rejected him, she was wrong [and] that Shaun is a great person and would make a great boyfriend," he says. "When he gives her crap at the end of that prior episode, she knows even then [and starts thinking], 'Was I wrong?' And in [the season 3 finale], as she listens to him, it reminds her of who he is as a human being [and] she realizes she was simply wrong. She doesn't change her mind."

The Good Doctor will return for season 4 on ABC.

Related content: