Number of final states in minimal DFA for $a^*b^*+b^*a^*$
Here are the Myhill–Nerode classes of your language:


$\epsilon$
$a^+$
$b^+$
$a^+b^+$
$b^+a^+$
Everything else.


To show this, you have to do two things:


Show that when in a specific class and reading a specific letter, you go to another specific class. This essentially amounts to constructing a DFA whose states are the classes.
Show that all the classes are distinct. You do this by giving separating words for every pair of classes.


After that, all that remains to be done is counting how many of these classes correspond to words in the language.