0

Please anyone help me with why this happens

The question url is this NIGHTS WATCH Q1: https://www.codechef.com/LTIME68B/problems/WTCH https://ide.geeksforgeeks.org/Y4U8qx #include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t>0){ t--; int n; cin>>n; int arr[n]; int indi=0,count=0; for(int i=0;i<n;i++) cin>>arr[i]; for(int i=0;i<n;i++){ if(i==0 && arr[0]==0 && arr[1]==0){ {arr[0]=1; count++; cout<<count; continue; } if(arr[i-1]==0&&arr[i+1]==0 && arr[i]==0 && i!=n-1){ {arr[i]=1; count++; cout<<count; } if(i==n-1 && arr[i-1]==0){ arr[i-1]=1; count++; cout<<count; } } } } cout<<count; } } I am not getting the desired out put the question link is provided on the top. Please tell me what is the mistake thanks in advanced.

26th Jan 2019, 3:57 PM
Balaji Pathange
Balaji Pathange - avatar
1 Answer
+ 2
The only problem I see is: [indentation]: in the last line the print statement is inside the for loop. But it should be indented to be inside the while loop. (only 4 spaces)
26th Jan 2019, 4:18 PM
Ulisses Cruz
Ulisses Cruz - avatar