Opening your workspace…
Workspace/Coding room
Opening your workspace…
You mind the chest room in a Minecraft base where nobody labels anything. When you ask for a sign to hang over the redstone chest, the builder says, “We've got a whole stack of signs.” He opens three chests full of cobblestone before he finds it.
Tonight you're hanging those signs. You line the regulars up at the door and hand each one a book. Starting with the chest nearest the door and working down the row, each player writes what they remember that chest holding. By the time they hand the books back, the builder has added “pretty sure” to the cover of his.
The input is the list of books. Each book contains one item name per chest, in the order the player visited them. Make your sign list in that same order. For each chest, take one vote from each book and use the item name with the most votes. A lead of one vote is enough. If two or more names tie for the lead, put "?" on that sign so you know to open the chest before you hang it.
[["coal","sand","iron_ingot"],["coal","gravel","flint"],["charcoal","sand","flint"]]Output["coal","sand","flint"]Coal, sand, and flint each receive two votes at their respective chests. The finished sign list differs from every individual book.
[["oak_log","torch"],["birch_log","torch"],["birch_log","stick"],["oak_log","coal"]]Output["?","torch"]Each kind of log gets two votes for the first chest. At the second chest, torch wins with two votes because stick and coal get one each.
Use a fresh tally for each column of the books.
function solve(books) { // Write your solution here. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.