What does it take to publish a YA or MG novel? Of course, it all depends on a number of factors. I will share with you what I learned in my Cognitive Psychology class. I studied under Anders Ericsson, the "expert on experts". He studies what it takes to be considered "expert" in various fields: sports, chess, and (you guessed it) writing.
For athletes, it takes 10-15 years of deliberate, helpful practice (you'll need a great coach) and you'll peak in your early 20s. After that, age works against you (typically). That's not to say that you should give up. Additional practice will help you fight against age and genetics plays a role as well.
For writers, well... we're luckier. It takes 10 years of deliberate practice. That's right. 10 years of writing GOOD fiction and GETTING BETTER. For 10 years! This involves getting good feedback, fixing your mistakes, growing as a writer and as a person, and gaining experience (both in writing and in the real world). I would argue that reading in your genre (especially reading as a writer) counts as practice. It's like a chess player studying the masters and memorizing helpful formations. The point is: it takes time and it's hard work.
Wait, I thought you said writers were lucky...
We are. Unlike every other discipline, writers don't peak in their twenties. We peak around 35 or 40. How cool is that?
If you want to see some interesting statistics, take a look at Selling Your First Children’s Novel: A Poll. If you're not familiar with the Tenners, they're a group of successful young adult and middle grade authors. This poll asks them about how they got their start. Some were fortunate and got offers right away. (I'll bet they were getting creative practice in other ways, though. Maybe by reading.) I'd like you to notice that none of them were under twenty when they got published. (And some were in their fifties.) You always hear about young first-time authors, but it's very rare.
So if you've been at it for several years, don't lose hope. Just like everything else, it takes hard work and patience.