Skip to the content

The kindergarten pots

Problem

In Miss Aurora's kindergarten there are two rows of pots against the yard wall, and each child looks after two pots in each row: the first two belong to the first child in alphabetical order, the next two to the second one, and so on to the end. The children line up by name, not in the order the teacher wrote them down.

In her notebook each pot is a letter: V for violets, R for radishes, M for mint and G for grass.

Write a function that takes rows, a list with two strings of those letters (the front row first and then the back one), and names, the list of the children's names. Return a dictionary with one name per key and, as the value, the list of that child's four plants: first the two pots in front and then the two in back, from left to right.

With the rows ["RM", "GG"] and the list ["Alice"], Alice is the only one, so she looks after the two pots in front and the two in back: you return {"Alice": ["radishes", "mint", "grass", "grass"]}.

Each row brings exactly two letters per child. If there are no children, you return an empty dictionary.

Examples

  • The example

    ["RM", "GG"], ["Alice"] → {"Alice": ["radishes", "mint", "grass", "grass"]}

  • Two children

    ["VVMG", "VVRM"], ["Alice", "Bob"] → {"Alice": ["violets", "violets", "violets", "violets"], "Bob": ["mint", "grass", "radishes", "mint"]}

  • The names arrive out of order

    ["VVMMGG", "VVMMGG"], ["Carol", "Alice", "Bob"] → {"Alice": ["violets", "violets", "violets", "violets"], "Bob": ["mint", "mint", "mint", "mint"], "Carol": ["grass", "grass", "grass", "grass"]}

  • Two names that start the same

    ["VRMG", "GMRV"], ["Alice", "Alan"] → {"Alan": ["violets", "radishes", "grass", "mint"], "Alice": ["mint", "grass", "radishes", "violets"]}

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def pots(rows, names):
    pass

JavaScript

function pots(rows, names) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n log n) challenges

See all challenges →