Why this code runs in leetcode compiler but not in codepen?

In leetCode compiler, below solution works fine but in codepen it returns only given input. Why? How to print same solution in codepen & other normal compilers?

For removing consecutive zero sum problem from Leetcode, I’m not getting Output as [1]. When same solution runs in codepen, getting output same as input [1,2,3,-3,-2].

function ListNode(val, next) {
        this.val = val;
        this.next = null; 
};
let removeZeroSumSublists = function(head) {
  // Initialize
  let dummy = {};
  dummy.next = head;
  const hm = new Map();
  let pSum = 0;
  hm.set(pSum, dummy);
  while(head){
    pSum += head.val;
    if(hm.has(pSum)){
      //remove entries
      let to_remove = hm.get(pSum).next, SUM = pSum;
      while(to_remove !== head){
        SUM += to_remove.val;
        hm.delete(SUM);
        to_remove = to_remove.next;
      }
      //draw link (delete nodes)
      hm.get(pSum).next = head.next;
    }
    else hm.set(pSum, head);
    head = head.next;
  }
  return dummy.next;
};

// To get output:-
let res1 = removeZeroSumSublists([1,2,3,-3,-2]);
console.log(res1);

// Input: head = [1,2,-3,3,1]
// Output: [3,1]

// Input: head = [1,2,3,-3,4]
// Output: [1,2,4]

// Input: head = [1,2,3,-3,-2]
// Output: [1]

@athiramelekappil @shivendra1751 @drishtinayak2828-TA @harshitrajlnctcse @Hiral_Khakhariya

1 Like

let me check @moni97kumar

Hey @moni97kumar in Leetcode also your code in not working, you can refer to this Solution

1 Like

Can you run only from removeZeroSumSublists function till return in leetcode? It works fine sir. My query why this same code not working under other compilers like Codepen, Vscode, etc. Can you check and give solution for how to run same code in other compilers? @shivendra1751

1 Like

Still not working, you can attach a screen shot.

In your code you are not reinitializing the value of psum to zero .

Working fine sir.

My query why this same leetcode solution not working under other compilers like Codepen, Vscode, etc. Can you check and give solution for how to run same code in other compilers instead of leetcode? @shivendra1751 @harshitrajlnctcse @athiramelekappil @drishtinayak2828-TA @Hiral_Khakhariya