I got this question through an email from the CTO of a company and gave my solution, but they didn’t tell me whether it was good or not, just that they’re moving into another candidate. What is this question called and where can I study it more?

I'd use ArrayLists for this. If he wants raw arrays for God knows what reason, I'd just convert all of them to arrays afterward. It's too much of a pain to deal with indices and allocation and whatnot.

public static ArrayList<ArrayList<Integer>> groupInts(ArrayList<Integer> arr) {
    ArrayList<ArrayList<Integer>> result = new ArrayList<>();
    ArrayList<Integer> current = new ArrayList<>();
    for(Integer num : arr) {
        // If the current list is empty, it obviously goes in there.
        // If the last element in current is adjacent, it also goes in there.
        if(current.isEmpty() || num - current.get(current.size()-1) <= 1) {
            current.add(num);
        }
        // Otherwise, we add current to the result and create a new empty current,
        // and add num to that.
        else {
            result.add(current);
            current = new ArrayList<>();
            current.add(num);
        }
    }
    if(!current.isEmpty()) {
        result.add(current);
    }
    return result;
}
/r/learnprogramming Thread