Staircase Search Code

https://ide.codingblocks.com/s/372598 This is what I have done for the staircase search. Is the code correct?

hello @diganta_7777

there was one small correction .
pls check it here->

Thank You for the correction! But will the program work without the condition? Is there any such test case where the program may run into runtime error?

yeah it(runtime) can happen .
consider this simple case
1 1 (dimension)
2 (only element)
-5 (target)

But it still worked(I guess it did unnecessary checking)… Suppose n has a large value, then I guess runtime can occur?(and the value is a negative one to be searched)? Am I on the right track?

no, it is not unecessary.
on cb ide it is working becuase it allows negative index on other ide it may fail (check on ur system ide).
also if u check ur output then u will find that it is printing -1 (value of j) which is clearly wrong (index should not be negative)

Oh like a[0][-1] indices like this

yeah…thats not correct

are checked by CB ide but fail in other ides?

yeah some ide dont allow negative index access and they will raise runtime error

Understood! Thanks!