the ques is balanced subarray;
here is my code just for test case 0and 1 it si no running but for rest it is running and i am getting 60/100
#include
using namespace std;
int main() {
int n;
cin>>n;
int cnt=0;
int cntt=0;
int ans=0;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
for(int i=0;i<n;i++){
if(arr[i]==0){
cnt++;
}else{
cntt++;
}
if(cnt==cntt){
ans=max(ans,cnt);
}
}
cout<<2*ans;
return 0;
}
Balanced subarray
Hey @diamond_saroha you are failing test casess which are of type
3
1 1 0
Here expected output is: 2
yours is giving: 0
Our Logic is to convert all 0’s to -1 and then find the max length subarray with 0 sum
You can take reference from this, and try to apply in your code too.
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.