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