# Getting "Time Limit Exceeded" although my code runs for under 100 ms

• I am getting a "Time Limit Exceeded" error although my code runs on my computer in less than 100 ms for the last executed output. I calculated, and I am getting the correct result too. There may be a better algorithm than the one I use, but it is not running out of time, atleast not for the "last executed input" that is shown. Any idea why?

public List<List<Integer>> permuteUnique(int[] nums)
{
//Step 1: form all combinations of indices of nums that start with with 0

``````Set<List<Integer>> indices = new HashSet<List<Integer>>();

Stack<List<Integer>> stack = new Stack<List<Integer>>();
List<Integer> root = new ArrayList<Integer>();
stack.push(root);

while(!stack.empty())
{
List<Integer> node = stack.pop();

if(node.size() < nums.length)
{
for(int i = 1; i < nums.length; i++)
{
if(!node.contains(i))
{
List<Integer> n = new ArrayList<Integer>();
stack.push(n);
}
}
}
else
}

//Step 2: Take the indices and cycle over the values of num to cover all permutations
Set<List<Integer>> permSet = new HashSet<List<Integer>>();

for(List<Integer> indexCombination : indices)
{
Set<Integer> roots = new HashSet<Integer>();
for(int i = 0; i < nums.length; i++)
{
{
List<Integer> temp = new ArrayList<Integer>();
for(int val : indexCombination)
}
}
}

ArrayList<List<Integer>> permList = new ArrayList<List<Integer>>();