I wasn't affected by bombing any classes and got direct admit to CS [^1], but there were classes of interest offered only once a year which filled up quickly. I just took them e.g., a year early than expected to make up for that or disregarded the prereqs and learned just enough on the fly. Another technique that helps is emailing the professor in advance of registration or after it's full and letting them how interested you are. Even better if you can stop by their office in person.
Another trick is to get into your school's Honors program which typically allows early registration vs non-Honors.
There were also 1-2 courses I audited for knowledge instead of officially taking which let me invest in basic learning without adding the pressure of a grade to a heavy course load.
Ideally everyone would have an academic advisor that lets them know this kind of thing in advance.
If I were graduating high school today, I would give serious consideration to Lambda School instead of a CS degree; though I also believe that we haven't seen enough time pass for the long-term implications of a decision like this to play out yet (e.g., future career discrimination based on lack of degree).
[^1]: I feel for people that don't get direct admit into their engineering major. This part feels unfair IMO. I think that everyone should be able to start in their desired major by default and disqualify out vs default out and qualify in.