Opening your workspace…
Workspace/Coding room
Opening your workspace…
Your little brother calls from the Infinite IKEA. He's sitting on a display bed under a sign that says BED. You ask him to be more specific. He checks under the pillow. It says PILLOW.
You have the store map. The showrooms repeat in one long aisle, and rooms lists their signs in order for one full lap. To meet him at the next staff door, you need to know where in the lap he started. Ask him to read his current sign, then walk forward one showroom at a time, reading each sign aloud. After the last room on the map comes the first again.
Given his actual starting index start, how many signs must you hear before you can tell it apart from every other index on the map? Count the sign he reads before walking. Return -1 if another starting position would sound just like his forever.
["BED","SINK","BED","SINK","LAMP"], 0Output3BED, SINK fits both index 0 and index 2. The third sign is BED from index 0 and LAMP from index 2.
["BED","DESK","BED"], 2Output2He reads BED and then crosses the end of the map to another BED. From the other bed he would read DESK next.
Compare the starting suffix with all other rotations using prefix-match lengths.
function solve(rooms, start) { // 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.