So, it says below "Along the main diagonal, all elements are true because everybody knows himself or herself." - this I assume is the last element from each generateRelationship array element. How am I supposed to interpret the following paragraph? " The intersection of rows and columns indicates whether people have friended each other (if true, then the people have friended each other). If a person with index k has been friended by a person with index p, then that means that the person with index k is among the friends of the person with index p." - like, where is this intersection? Requirements: How many potential friends does a person have? Today we'll analyze some functionality of social networks. How do social networks know who to suggest as friends you might know? This task is easily solved using graphs. Your task is to implement the Set<Integer> getAllFriendsAndPotentialFriends(int index, int deep) method, which returns the indices of people you are already friends with and of people you might know. After that, the removeFriendsFromSet method will run and produce the set of all potential friends of the person with the passed index, given a search depth specified by the deep parameter. For simplicity, we will view everyone's relationships as a two-dimensional array called humanRelationships (see an example array in the generateRelationships method). Along the main diagonal, all elements are true because everybody knows himself or herself. The intersection of rows and columns indicates whether people have friended each other (if true, then the people have friended each other). If a person with index k has been friended by a person with index p, then that means that the person with index k is among the friends of the person with index p. Two arguments are passed to the method: int index - the index of a person in the array (starting from zero); int deep - how deep to search for friends. If Mary is Natalie's friend and Julia is Mary's friend and the search depth = 1, then you need to add Mary to the set returned for Natalie. If the search depth = 2, then you need to add Mary, along with Julia as a potential friend, to the set returned for Natalie. If the search depth = 3, then you also need to add all of Julia's friends to the same set. See the example in the main method. The set returned by the getAllFriendsAndPotentialFriends method must not include index. Requirements: 1. The Solution class must have a public Set<Integer> getAllFriendsAndPotentialFriends(int index, int deep) method. 2. The Solution class must have a boolean[][] humanRelationships class. 3. The set returned by the getAllFriendsAndPotentialFriends method must not include index. 4. The getAllFriendsAndPotentialFriends method must be implemented as outlined in the task conditions.
public class Solution {
    private boolean[][] humanRelationships;

    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.humanRelationships = generateRelationships();

        Set<Integer> allFriendsAndPotentialFriends = solution.getAllFriendsAndPotentialFriends(4, 2);
        System.out.println(allFriendsAndPotentialFriends);                              // Expected: [0, 1, 2, 3, 5, 7]
        Set<Integer> potentialFriends = solution.removeFriendsFromSet(allFriendsAndPotentialFriends, 4);
        System.out.println(potentialFriends);                                           // Expected: [2, 5, 7]
    }

    public Set<Integer> getAllFriendsAndPotentialFriends(int index, int deep) {
        //write your code here
        Set<Integer> result = new HashSet<>();
        if (deep == 0) {
            return result;
        } else {
            for (int i = 0; i < humanRelationships.length; i++) {
                if ((i < index) && (index < humanRelationships.length) && humanRelationships[index][i]) {
                    result.add(i);
                } else if ((i > index) && humanRelationships[i][index]) {
                    result.add(i);
                }
            }
            Object[] arrayToProcess = result.toArray();
            for (Object value : arrayToProcess) {
                result.addAll(getAllFriendsAndPotentialFriends((Integer) value, deep - 1));
            }
            result.remove(index);
        }
        return result;

    }

    // Remove from the set the people with whom you already have a relationship
    public Set<Integer> removeFriendsFromSet(Set<Integer> set, int index) {
        for (int i = 0; i < humanRelationships.length; i++) {
            if ((i < index) && (index < humanRelationships.length) && humanRelationships[index][i]) {
                set.remove(i);
            } else if ((i > index) && humanRelationships[i][index]) {
                set.remove(i);
            }
        }
        return set;
    }

    // Return test data
    private static boolean[][] generateRelationships() {
        return new boolean[][]{
                {true},                                                                 //0
                {true, true},                                                           //1
                {false, true, true},                                                    //2
                {false, false, false, true},                                            //3
                {true, true, false, true, true},                                        //4
                {true, false, true, false, false, true},                                //5
                {false, false, false, false, false, true, true},                        //6
                {false, false, false, true, false, false, false, true}                  //7
        };
    }
}