package leetcode;

import java.util.Arrays;
import java.util.List;

/**
 * https://leetcode.com/problems/keys-and-rooms/
 */
public class Problem841 {
    public boolean canVisitAllRooms(List<List<Integer>> rooms) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem841 prob = new Problem841();
        System.out.println(prob.canVisitAllRooms(Arrays.asList(
            Arrays.asList(1),
            Arrays.asList(2),
            Arrays.asList(3),
            Arrays.asList())
        )); // true
        System.out.println(prob.canVisitAllRooms(Arrays.asList(
            Arrays.asList(1, 3),
            Arrays.asList(3, 0, 1),
            Arrays.asList(2),
            Arrays.asList(0)
        ))); // false
    }
}

@@ -221,37 +221,692 @@
     
-// TODO%0A        return false;
+boolean%5B%5D visited = new boolean%5Brooms.size()%5D;%0A        visited%5B0%5D = true;%0A        canVisitAllRooms(rooms, rooms.get(0), visited);%0A        boolean result = true;%0A        for (boolean v : visited) %7B%0A            if (!v) %7B%0A                return false;%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A    private static void canVisitAllRooms(List%3CList%3CInteger%3E%3E rooms,%0A                                         List%3CInteger%3E keys,%0A                                         boolean%5B%5D visited) %7B%0A        for (int key : keys) %7B%0A            if (!visited%5Bkey%5D) %7B%0A                visited%5Bkey%5D = true;%0A                canVisitAllRooms(rooms, rooms.get(key), visited);%0A            %7D%0A        %7D
 %0A   

Solve problem 841