亚麻onsite遇到的一道题

题目: https://leetcode.com/problems/subsets/

The dfs solution would be something like this:

private void backtrack(List<List<Integer>> res , List<Integer> list, int[] nums, int start){
        System.out.println(list);
        res.add(new ArrayList<>(list));
        for (int i = start; i < nums.length; i++) {
            list.add(nums[i]);
            backtrack(res, list, nums, i + 1);
            list.remove(list.size() - 1);
        }
    }

Now the follow-up question is to remove that for loop from backtrack funtion and pass the indexes. I tried to keep i index by passing it to the function by couldn’t figure out the index incrementing logic.