Opening your workspace…
Workspace/Coding room
Opening your workspace…
Dwight has appointed you roll-call captain for the Dunder Mifflin fire drill. Your instructions are to stay in the parking lot, take down the name of every employee who reports to you, and radio Dwight the moment the entire floor is accounted for.
Kevin reports in. Then Kevin reports in again. He wants to know whether you spelled it right. You cross out the second Kevin. Dwight objects over the radio: the clipboard is the official record of the drill, and it is against procedure to cross things out on the official record of the drill.
Fine. Find the earliest stretch of exactly k consecutive check-ins where every name is different. The floor has k employees, and only employees from that floor can check in. Return the index of the first name in that stretch, counting from zero, or -1 if Dwight never gets his roll call.
["Jim","Pam","Jim","Kevin"], 3Output1Pam, Jim, and Kevin check in consecutively starting at index 1.
["Dwight","Angela","Dwight"], 2Output0The first two check-ins already account for both employees.
Track the last index of each name and the start of the current distinct stretch.
function solve(checkIns, k) { // 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.