The full account of this lifetime is told in the Maha-Ummagga Jataka (#546), while the Mendaka Jataka only relates this single incident from that story.
The Bodhisatta was once a king’s advisor. One day King Vedeha went for a morning walk and saw a goat and a dog, natural enemies, being friendly. The goat fed on the grass thrown to the elephants at their stable, running in to eat before the elephants arrived. But when the mahouts saw the goat, they beat him away. The dog lived on the bones, skin, and other scraps from the royal kitchen, but that same day, he lost patience and snuck inside the kitchen to eat cooked meat. The cook saw the dog and beat him with sticks and stones. The two suffering animals met and shared their tales of woe, both depressed because they would never be able to return to their feeding spots for risk of death. But as they talked, the goat came up with the plan that he would go to the kitchen and bring back meat, while the dog would go to the elephant stables for a bundle of grass. Nobody would pay them any attention because their species don’t eat those foods, and they could bring them to the palace wall and eat together.
The king was astonished by their friendship and wondered if his advisors could figure out how it happened. When they next met, the king asked them, “Two natural enemies have become inseparable friends: what is the reason?” and said he would banish any of them who couldn’t figure it out because he didn’t want stupid men around him. Knowing the king wasn’t smart enough to create a riddle, the Bodhisatta realized he must have seen something. He went to ask Queen Udumbara where King Vedeha had been for most of the day before, and she mentioned he had done a lot of walking alongside the palace wall and staring out his window. The Bodhisatta went to the palace wall and found the dog and goat, and he watched them to figure out their story.
The other four advisors came to the Bodhisatta, knowing he would find the answer, and asked for help. He agreed, but instead of telling them the answer directly, he taught them each a stanza in a language they didn’t know but that the king did. And the next day, when they were asked to give answers, they recited the stanzas by memory, and the king believed they knew. After the Bodhisatta gave a longer, more detailed answer, the king showed his pleasure by giving each of the men a chariot, a mule, and a wealthy village.
In the Lifetime of the Buddha
One day some of the Buddha’s disciples were discussing his supreme wisdom; in particular, how he had humbled and converted a vast multitude of brahmins, ascetics, thieves, goblins, gods, and more. When the Buddha heard them talking about it, he told them this story so they knew that he’d also had perfect knowledge in the past.
King Vedeha was an earlier birth of Laludayi, an elder disciple of the Buddha who was so shy that he could not speak when around more than a single other person, and he often said one thing when he meant another. The king’s chief advisor was an earlier birth of Saccaka, a Jain who converted to be a disciple of the Buddha, and the other three advisors were earlier births of Potthapada, Ambattha, and Pilotika, three ascetics who respected the Buddha.