Vradhit – 14-13 Jul 30

can anyone please tell me why this telling maximum callstack exceeded in this snippet of leetcode
var permute = function(nums) {


let res = [];
let temp = [];
backtrack(nums,temp,0);
return res;

function backtrack(nums,temp,start)
{
if(start===nums.length){
res.push([...temp])
return;

}

for(let i=0;i<nums.length;i++){

temp.push(nums[i]);
backtrack(nums,temp,i+1);
temp.pop();

}



}


};
var permute = function(nums) {


let res = [];
let temp = [];
backtrack(nums,temp,0);
return res;

function backtrack(nums,temp,start)
{
if(start===nums.length){
res.push([...temp])
return;

}

for(let i=0;i<nums.length;i++){

temp.push(nums[i]);
backtrack(nums,temp,i+1);
temp.pop();

}



}


};
UU
Unknown User627d ago
V
Vradhit627d ago
I changed i to start now the error is not there but i am not getting permuation results Wrong Answer Runtime: 91 ms Your input [1,2,3] Output [[1,2,3],[1,3],[2,3],[3]] Expected [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] /** * @param {number[]} nums * @return {number[][]} */
var permute = function(nums) {


let res = [];
let temp = [];
backtrack(nums,temp,0);
return res;

function backtrack(nums,temp,start)
{
if(start===nums.length){
res.push([...temp])
return;

}

for(let i=start;i<nums.length;i++){

temp.push(nums[i]);
backtrack(nums,temp,i+1);
temp.pop();

}



}


};
var permute = function(nums) {


let res = [];
let temp = [];
backtrack(nums,temp,0);
return res;

function backtrack(nums,temp,start)
{
if(start===nums.length){
res.push([...temp])
return;

}

for(let i=start;i<nums.length;i++){

temp.push(nums[i]);
backtrack(nums,temp,i+1);
temp.pop();

}



}


};
UU
Unknown User627d ago
V
Vradhit627d ago
actually that internally backtrack works for loop
UU
Unknown User627d ago