Back to questionsDSA Visualizers: 388 Coding Questions Largest Zero Sum Subarray visualizer Learn Largest Zero Sum Subarray with a step-by-step Arrays visualizer, JavaScript source code and a worked example. Practice hashing and prefix sums.
INTERACTIVE EXECUTION STUDIOLEARN BY DOING Predict. Execute. Understand. Follow the source code, inspect live state changes, and predict the next operation before revealing it.
1 / 7 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input [
1,
2,
-3,
3,
-3,
5
] Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = (a,s)=>{
2 let m=new Map([[0 ,-1 ]]),v=0 ,b=0 ;
3 a.forEach((x,i)=>{
4 v+=x;
5 if (m.has(v))b=Math.max(b,i-m.get(v));
6 else m.set(v,i);
7 s("Find repeated prefix",{
8 Array:a,Prefix:[v],Best:[b]
9 },[i])
10 });
11 return b
12 };
Execution canvas Active ChangedSTEP 1 Find repeated prefix Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.
Worked example and algorithm walkthrough Topic: Arrays · Hashing and prefix sums
Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.
Example input [
1,
2,
-3,
3,
-3,
5
] Execution steps Find repeated prefix Computed output 5 JavaScript reference implementation const solve = (a,s)=>{
let m=new Map([[0,-1]]),v=0,b=0;
a.forEach((x,i)=>{
v+=x;
if(m.has(v))b=Math.max(b,i-m.get(v));
else m.set(v,i);
s("Find repeated prefix",{
Array:a,Prefix:[v],Best:[b]
},[i])
});
return b
};Continue learning Practice related DSA questions in the same topic.