You are in a house where the light in each room is controlled by a switch that might be located in a different room. Initially, the light in the first room is on, and the lights in all the other rooms are off.
You are currently in the first room and your goal is to end up in the last room, with all the lights in the house off except the light in the last room. You can move directly from any room to any other room, and you can turn any of the switches that are located in your current room. However, you may never enter a dark room or turn off the light in your current room.
You are given a int[] switches describing the locations of the light switches. The light switch for room i is located in room switches[i]. Rooms have 0-based indices. Return the minimal number of moves required to complete your task, or -1 if it is impossible. Only moving from one room to another counts as a move (turning a switch is not counted).
|