Maximum circles

in this code

int C=1;

int end=arr[0].center+arr[0].radius;
for(int i=1;i<N;i++)
{
    int srt=arr[i].center-arr[i].radius;
    if(end<=srt)
    {
        C++;
        end=arr[i].center+arr[i].radius;
    }
}

why this statement is inside the if statement
end=arr[i].center+arr[i].radius;

for suppose

1 1

3 1

4 1

in this the first two circles dont overlap so but the third one does and if this dont satisy my if statement then my end will be 1 circles end only but the 3 circle overlaps with 2 circle i know answer will be correct as c=1 but logic wise its going wrong as per me. can u explain me

hello @saiKDr

first we consider our first cirlce -> (1,1) that means end=2
now left end of second circle (3,1) is (3-1) =2
clearly end <= 2 so that means second circle dont overlap hence we increment out c by 1 (now it will be 2) and update our end (now it will be 3+1 i,e 4).

sofar our c=2 , end=4
now we come to third circle (4,1) left end of third circle is (4-1)=3
is our end <= 3? no
so we dont do anything.

now loop is done
final status - > c=2 .(c is telling us the maximum number of non overlaping cirlce but in answer we need to print count of circle that we should remove).
so we print n-c-> 3-2=1
this 1 is telling that if we remove 1 circle then remaing all cirlces will be non overlapping

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.