Students arrive at college with different levels of understanding about what they want to study. I knew from the first it would be mathematics. My daughter only chose her major study (philosophy) after three years of study, having studied many things already. The latter case is unusual and most choose initially or after about one year.
In many, perhaps most universities, every student is at some point chooses or is assigned a faculty member as an advisor who meets with the student to plan for the coming terms, according to the interests of the student at the time. In large universities the early advisement might be by a special office rather than a faculty member. In general, though, students have a way to get advice on planning the path to the degree.
There are limitations in that there is a core undergraduate set of courses that must be taken. Everyone takes a bit of, say, history, science, philosophy, writing, literature, etc. in addition to any chosen major.
Once you have a major, you have an additional set of core requirements. In math it will include analysis, algebra, probably topology, etc. These are normally started in the first years. The advisor has the duty of giving good advice on course sequencing.
Choosing a minor subject will also have core requirements and some later options. Where I studied a "minor" in philosophy was almost guaranteed due to the overall core requirements. A minor has, say, about half as many courses needed as the major.
A student in math and a student in literature will, perhaps, share a course or two in the first year, but not likely afterwards.
The final two years are more specialized with fewer required courses and more options in the major and (perhaps) any minor(s) chosen. All this is guided by the advisor who meets with the student for course planning and possibly other academic advice. One normally has the same advisor over all four years, but, perhaps not, especially if the major is chosen later. You want an advisor who is a faculty member in your major.
Note that the advisor is guided by somewhat flexible rules. A certain number of courses is required for this and for that and courses have some sequencing requirements, but exceptions are possible and not necessarily rare. I had an exception made for my foreign language requirement, for example, having studied both French and German, but not quite enough to satisfy the requirement for either. For that, the dean needed to approve and took my overall trajectory into account.
In the upper level courses you are likely to see many of the same students in your classes, but this depends on the size of the institution. My undergrad place was small, and I could depend on having two fellow (yes, fellow - all male college) students in all my upper level courses and a few others in some others. At a large place, this might not happen as often.
Even in US grad school with advanced courses at the start, you would see many of the same students in the courses intended to prepare for comprehensive exams.
Note that US higher education isn't like a production line, with everyone getting the same treatment and everyone progressing at the same rate. If students fail, they might retake the course or find an alternative, even changing majors. Retaking final exams after a failed course probably isn't an option here. I've never heard of it anyway.
The education is much broader and is intended to form an "educated person", not a technocrat, though some specialties have that characteristic (law, medicine...). The system in general has been described as producing a Renaissance Person.
Some detail, typical, but not universal as there are a couple of popular systems:
An undergraduate program might consist of 16 "credits" per term for 8 terms or 128 credits overall. This might be four or five courses per term or maybe six, with some having less weight and some more (lab science). Overloads are possible. I once did 21.5 credits in a successful term. A "credit" is roughly equivalent to meeting one hour per week in a course, so a 3 credit course has three meetings per week over about 15 weeks or 45 hours of instruction, including exams.
The major might be in the neighborhood of 48 or so credits or around 40% of the total. Many students take more in the major than the minimum. A minor might be around half of the major.
Some places (Dartmouth for example) use a different system with things divided up differently, but the totals roughly the same.