Doubt in my code

Hello, here is my code :

Why it is giving me error ?

Hey @yashsharma4304
Mentioned the changes in comments :slight_smile:

1 Like

Why do I need to initialize max with 0?

Then it may start with any garbage value , maybe infinity :slight_smile:

//if giving segmentation then declare them dynamically

And What does it mean ?

But I have initialized it with inc[0] + dec[0] -1 ?

Oh missed that ,then ignore that change :stuck_out_tongue:

1 Like

Max array size inside function is close to 10^6 , so sometimes when u create array of that size inside function then it may give segmentation error because u run out of memory in stack
Hence we have to declare the arrays dynamically in that case

1 Like