What you missed in your approach to the question is that there is nothing in the problem statement that prevents bus $B$ from arriving after $4$ pm, and in fact (assuming uniform, independent distributions of the arrival times) half the time bus $B$ will arrive after $4$ pm,
and in that case bus $A$ will have arrived first.
Likewise, there is nothing that requires bus $A$ to arrive after $3$ pm so that bus $B$ has a chance to arrive first. Bus $A$ can just as likely arrive before $3$ pm.
Let's take a frequentist approach. Suppose that these two buses run on this random schedule seven days a week, every day of the year. Let's watch them arrive for a few days and see what happens. Here's one possible way this might unfold:
On Monday, bus $A$ arrived at $2{:}38$ and bus $B$ arrived at $3{:}02$.
Although bus $B$ arrived almost as quickly as it possibly can, bus $A$ still arrived first.
On Tuesday, bus $A$ arrived at $3{:}05$ and bus $B$ arrived at $3{:}42$.
Bus $A$ arrived first.
On Wednesday, bus $A$ arrived at $2{:}50$ and bus $B$ arrived at $4{:}11$.
Bus $A$ arrived first.
On Thursday, bus $A$ arrived at $3{:}57$ and bus $B$ arrived at $4{:}30$.
Bus $A$ arrived first even though it was almost as late as it can be.
On Friday, bus $A$ arrived at $2{:}05$ and bus $B$ arrived at $4{:}56$.
Bus $A$ arrived first.
On Saturday, bus $A$ arrived at $3{:}19$ and bus $B$ arrived at $3{:}17$.
Finally we have observed an event in which bus $B$ arrived first!
In the long run, if we keep track of the relative frequency of days like Monday
(when bus $A$ arrives before $3$ pm and bus $B$ arrives between $3$ and $4$ pm),
we'll find that the relative frequency approaches $1/4$ of all the days.
To put it simply, in the long run $1/4$ of the days will be like Monday.
Similarly, in the long run $1/4$ of the days will be like Wednesday and Friday, when bus $A$ arrived before $3$ pm and bus $B$ arrived after $4$ pm.
Another $1/4$ of the days will be like Thursday, when bus $A$ arrived between $3$ and $4$ pm but bus $B$ arrives after $4$ pm.
That leaves just $1/4$ of the days in the long run when bus $A$ and bus $B$ both arrive between $3$ and $4$ pm. One half of those days ($1/8$ of all days in the long run) will be like Tuesday, when bus $A$ arrived first, and the other half of those days ($1/8$ of all days in the long run) will be like Saturday, when bus $B$ arrived first.
And that accounts for all possibilities. In one case, which happens $1/8$ of the time, bus $B$ arrives first. In all other cases bus $A$ arrives first.