Giving wrong ans :(

@Muskan-Gupta-598128740703036,
Wrong link…:slightly_frowning_face:

pura code likha tha abhi , save bhi kiya …abh pta nhi kyu show nhi krra

second time, same wa

@Muskan-Gupta-598128740703036,
Nope, still no code, please try saving it on any other online IDE, ideone maybe.

sir??? aapne code dekha??

@Muskan-Gupta-598128740703036,
The l,r,x,y given in problem are 1 based indexed, but the array on which you build the tree is 0 based
buildTree(arr,0,n-1,tree,1); - > …0,n-1…

showing wrong ans on submission but given sample case is running perfect

sir?? its showing wrong ans

i am waiting for reply

Hey @Muskan-Gupta-598128740703036,

Here is the correct code ( I have attached the ideone link as well incase cb ide does not show the code):

ERRORS:

  1. You need to initialize tree as -1.
  2. Use long everywhere possible.
  3. Instead of taking arr of size n+1 take it as n only and build tree from 0 to n-1 instead of 1 to n. Also input should be from 0 to n-1 instead of 1 to n as you had done.
  4. In the updatenode method, there was an error. You had written tree[index] += increment; which should be tree[index] = increment;

If you have any further queries kindly reply to this thread, I would be happy to help :smile: :blush:

Thankyou sir , ho gya and samjh aa gya ! :slight_smile: