- 1

Coding Time ⌚

Lets who can do this first: Any language allowed-> You are given an array A of N positive integer values.A sub array of this array is called Odd Even subarray if the number of odd integers in this subarray is equal to the number of even integers in this sub array. Find the number of Odd Even sub arrays for the given sub array. Sample Input: 4 //array size 1 2 1 2 // array elements Sample output: 4 //Total number of oddeven subarrays. (1,2),(2,3),(3,4),(4,1)

17th Mar 2018, 2:03 PM
Mohd Zaki
Mohd Zaki - avatar
2 Answers
+ 11
Looks like a challenge. Kindly post it in the lesson factory under assignments. Thanks.
17th Mar 2018, 4:42 PM
Harsh
Harsh - avatar
+ 2
Here the source code #include<stdio.h> void main(){ int num,i,arr[500],e=0,o=0,odd=0,even=0,j,k,count=0; scanf("%d", &num); // Reading input from STDIN printf("Input number is %d\n", num); // Writing output to STDOUT for(i=0;i<num;i++) { scanf("%d",&arr[i]); } for(i=0;i<num;i++) { if(arr[i]%2==0) { odd++; } else { even++; } } if(odd==even) { for(i=0;i<num;i++) { for(j=i;j<num;j++) { for(k=i;k<=j;k++) { if(arr[k]%2==0) { e++; } else { o++; } if(e==o) { count++; } } } } printf("%d",count); } }
17th Mar 2018, 2:51 PM
ayush jain
ayush jain - avatar