As @vonbrand suggested, using one automata (without attempting to combine them) is sufficient. Combining them will prove to be more work than it's worth.
Basically, here's the idea:
- If you get an $a$, begin looping on $a^nb$. If you get a $b$ after this, accept. But anything further goes to the trash can.
- If you get a $b$, accept for $a^0b$. If you get another $b$, you can then loop on $b$ under $b^na$. At any point in the loop, if you get an $a$, accept. But if you get anything after that $a$, go to the trash can.
Here is a textual representation (
t is the "trash can" or trap state;
+ represents an accept state).
| 0 | 1 | 2+ | 3+ | 4+ | 5
a | 1 | 1 | 4 | t | t | 4
b | 2 | 3 | 5 | t | t | 5
And here is a generated visual version:
(I'm not 100% sure this is minimal, but if it's not, it's a good exercise.)