trays (no letter repeats there).
The letters of letters enter the machine one by one, from left to right. Each letter falls into the tray with its own label. If there is no such tray, the letter falls into the very first (leftmost) tray. Within a tray, letters stay in the order they arrived.
Once every letter is sorted, the machine empties the trays from left to right. Return the resulting string.trays="tea", letters="eatbet" → 'tbteea'
The trays from left to right are t, e, a. There is no tray for b, so it falls into the first tray together with the ts, in order of arrival: t, b, t. Then come e, e and a, giving "tbteea".
trays="kq", letters="qkq" → 'kqq'
First the k tray with one letter, then the q tray with two.
trays="z", letters="hello" → 'hello'
traystrays="tea", letters="eatbet"
'tbteea'
Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.