Can someone debug my code .

https://codeshare.io/5X1z78

Lasers

Can you elaborate what and why you did inside the for loop from x1 to x2.

m is the slope which is (y2-y1)/(x2-x1).

We know that (x2-x1)=1.

c is constant.

So i basically made an equation of the form “y=mx+c”

Now we know m and c.

Now, i replaced y in the above equation with the y that we’ve taken as input and found out x.

If x lies in the interval then it intersects the line otherwise not.

The example inputs are working fine.

I am not sure why you needed slope, but very simply this would have worked :-

if((a[i]<=y && a[i+1]>=y) || (a[i]>=y && a[i+1]<=y)){

cnt++;

}

for x1 to x2

should the loop goes till x2 or <x2 ?