On two Combinatorial Problems Arising from Automata Theory