Opening your workspace…
Workspace/Coding room
Opening your workspace…
You’re doing wires in Electrical on the Skeld. You pull the red wire across the panel and stop just short of plugging it in. The colored caps from the right-hand sockets are sitting in a neat little pile on the floor. Yellow leans in from the hallway. “I sorted them for you.” They are, in fact, in rainbow order.
The lettering on the left wires is still legible, and the right sockets are numbered from 0, top to bottom. Each left wire has a matching socket connected to the same circuit. To find it, you can clip the tester to several loose wires at once. The lamp beside every matching socket lights up. The tester records which wires you clipped and which sockets lit, but the order within either list means nothing.
Given the wire names in panel order and the records of your tests, work out which connections you can safely make. Return one socket number per wire, in panel order. Use a number only if every one-to-one wiring consistent with all the tests pairs that wire with that socket. Otherwise return -1 for that wire.
["red","blue","yellow","pink"], [[["red","blue"],[0,2]],[["blue","yellow"],[3,0]]]Output[2,0,3,1]Blue was clipped both times, and only socket 0 lit twice. That leaves socket 2 for red in the first test and socket 3 for yellow in the second. Pink gets the remaining socket, 1.
["pink","yellow","red","blue"], [[["red","pink"],[3,1]],[["yellow"],[0]]]Output[-1,0,-1,2]Pink and red could swap sockets 1 and 3 without changing either record. Yellow goes to socket 0. Blue was never clipped, so its socket must be 2, the only one that stayed dark.
A wire and its socket must share the same membership pattern across all tests. Which patterns occur just once?
function solve(wires, tests) { // 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.