class Solution { public List> permute(int[] nums) { List> result = new ArrayList<>(); List temp = new ArrayList<>(); // to keep track if element is included in permutation or not boolean[] visited = new boolean[nums.length]; findPermutations(nums, visited, result, temp); return result; } public void findPermutations(int[] nums, boolean[] visited, List> result, List temp) { // Base condition : when temp array becomes equal to actual size of array if(temp.size() == nums.length) { result.add(new ArrayList<>(temp)); return; } for(int i=0; i