Computer Science, asked by palji1852, 1 year ago

find the largest subarray with equal number of 0's and 1's

Answers

Answered by jonathancarr
0

According to all known laws


of aviation,


 


there is no way a bee


should be able to fly.


 


Its wings are too small to get


its fat little body off the ground.


 


The bee, of course, flies anyway


 


because bees don't care


what humans think is impossible.


 


Yellow, black. Yellow, black.


Yellow, black. Yellow, black.


 


Ooh, black and yellow!


Let's shake it up a little.


 


Barry! Breakfast is ready!


 


Ooming!


 


Hang on a second.


 


Hello?


 


- Barry?


- Adam?


 


- Oan you believe this is happening?


- I can't. I'll pick you up.


 


Looking sharp.


 


Use the stairs. Your father


paid good money for those.


 


Sorry. I'm excited.


 


Here's the graduate.


We're very proud of you, son.


 


A perfect report card, all B's.


 


Very proud.


 


Ma! I got a thing going here.


 


- You got lint on your fuzz.


- Ow! That's me!


 


- Wave to us! We'll be in row 118,000.


- Bye!


 


Barry, I told you,


stop flying in the house!


 


- Hey, Adam.


- Hey, Barry.


 


- Is that fuzz gel?


- A little. Special day, graduation.


 


Never thought I'd make it.


 


Three days grade school,


three days high school.


 


Those were awkward.


 


Three days college. I'm glad I took


a day and hitchhiked around the hive.


 


You did come back different.


 


- Hi, Barry.


- Artie, growing a mustache? Looks good.


 


- Hear about Frankie?


- Yeah.


 


- You going to the funeral?


- No, I'm not going.


 


Everybody knows,


sting someone, you die.


 


Don't waste it on a squirrel.


Such a hothead.


 


I guess he could have


just gotten out of the way.


 


I love this incorporating


an amusement park into our day.


 


That's why we don't need vacations.


Read more on Brainly.in - https://brainly.in/question/5997695#readmore

Answered by fabuco
0

Input: arr[] = {1, 0, 1, 1, 1, 0, 0}

Output: 1 to 6 (Starting and Ending indexes of output subarray)

Input: arr[] = {1, 1, 1, 1}

Output: No such subarray

Input: arr[] = {0, 0, 1, 1, 0}

Output: 0 to 3 Or 1 to 4



#include <bits/stdc++.h>

using namespace std;

void largestSubarray(int arr[], int n)

{

 

int maxsize = -1; //to upddate the maximum size of subarray

int start_index = 0;

for (int i = 0; i < n-1; ++i)

{

 int sum = 0;

 if(arr[i] == 0) //considering all zeroes as -1

 {

  sum = -1;

 }

 else

 {

  sum = 1;

 }

 for (int j = i+1; j < n; ++j)

 {

  if(arr[j]==0)

  {

   sum = sum - 1; //finding sum of the subarray

  }

  else

  {

   sum = sum + 1;

  }

  if(sum == 0 && (j - i +1) > maxsize )

  {

   maxsize = j-i+1;

   start_index = i;

  }

 }

}

cout<<"Start index is "<<start_index<<" and ";

cout<<"End index is "<<maxsize + start_index -1<<endl;

for (int i = start_index; i <= (start_index + maxsize -1); ++i)

{

 cout<<arr[i]<<" ";

}

}

int main()

{

int arr[]= {1, 1, 0, 1, 0};  //creating an array

int n = sizeof(arr)/sizeof(arr[0]); //size of the array

largestSubarray(arr, n);

return 0;

}

Similar questions