Array Manipulation | HackerRank

Getting segmentation fault in few test cases. can someone help me to find out the error??

I’m guessing you’re using too much stack space (N can be as high as 10^7, remember, which is approx 80MB of stack for your array d).

Try making d a std::vector instead.

2 Likes

I don’t think you should be making an array of size n in the first place. Notice only 2m indexes have any importance.

bro your code consists of d[b] and it will go into array out of bound exception…
So, try putting a condition that if b==length of your array then don’t decrement the value