Number of sub arrays with odd sum
Last Updated :
07 Jan, 2024
Given an array, find the number of subarrays whose sum is odd.
Examples:
Input : arr[] = {5, 4, 4, 5, 1, 3}
Output : 12There are possible subarrays with odd
sum. The subarrays are
1) {5} Sum = 5 (At index 0)
2) {5, 4} Sum = 9
3) {5, 4, 4} Sum = 13
4) {5, 4, 4, 5, 1} Sum = 19
5) {4, 4, 5} Sum = 13
6) {4, 4, 5, 1, 3} Sum = 17
7) {4, 5} Sum = 9
8) {4, 5, 1, 3} Sum = 13
9) {5} Sum = 5 (At index 3)
10) {5, 1, 3} Sum = 9
11) {1} Sum = 1
12) {3} Sum = 3
O(n2) time and O(1) space method [Brute Force]: We can simply generate all the possible sub-arrays and find whether the sum of all the elements in them is an odd or not. If it is odd then we will count that sub-array otherwise neglect it.
Implementation:
C++
// C++ code to find count of sub-arrays with odd sum
#include <bits/stdc++.h>
using namespace std;
int countOddSum(int ar[], int n)
{
int result = 0;
// Find sum of all subarrays and increment result if sum
// is odd
for (int i = 0; i <= n - 1; i++) {
int val = 0;
for (int j = i; j <= n - 1; j++) {
val = val + ar[j];
if (val % 2 != 0)
result++;
}
}
return (result);
}
// Driver code
int main()
{
int arr[] = { 5, 4, 4, 5, 1, 3 };
int n = sizeof(arr) / sizeof(arr[0]);
cout << "The Number of Subarrays with odd sum is "
<< countOddSum(arr, n);
return (0);
}
// This code is contributed by Sania Kumari Gupta
C
// C++ code to find count of sub-arrays with odd sum
#include <stdio.h>
int countOddSum(int ar[], int n)
{
int result = 0;
// Find sum of all subarrays and increment result if sum
// is odd
for (int i = 0; i <= n - 1; i++) {
int val = 0;
for (int j = i; j <= n - 1; j++) {
val = val + ar[j];
if (val % 2 != 0)
result++;
}
}
return (result);
}
// Driver code
int main()
{
int arr[] = { 5, 4, 4, 5, 1, 3 };
int n = sizeof(arr) / sizeof(arr[0]);
printf("The Number of Subarrays with odd sum is %d",
countOddSum(arr, n));
return (0);
}
// This code is contributed by Sania Kumari Gupta
Java
// Java code to find count of sub-arrays with odd sum
import java.io.*;
class GFG {
static int countOddSum(int ar[], int n)
{
int result = 0;
// Find sum of all subarrays and increment result if
// sum is odd
for (int i = 0; i <= n - 1; i++) {
int val = 0;
for (int j = i; j <= n - 1; j++) {
val = val + ar[j];
if (val % 2 != 0)
result++;
}
}
return (result);
}
// Driver code
public static void main(String[] args)
{
int ar[] = { 5, 4, 4, 5, 1, 3 };
int n = ar.length;
System.out.print(
"The Number of Subarrays with odd sum is ");
System.out.println(countOddSum(ar, n));
}
}
// This code is contributed by Sania Kumari Gupta
Python3
# Python 3 code to find count
# of sub-arrays with odd sum
def countOddSum(ar, n):
result = 0
# Find sum of all subarrays and
# increment result if sum is odd
for i in range(n):
val = 0
for j in range(i, n ):
val = val + ar[j]
if (val % 2 != 0):
result +=1
return (result)
# Driver code
ar = [ 5, 4, 4, 5, 1, 3 ]
print("The Number of Subarrays" ,
"with odd", end = "")
print(" sum is "+ str(countOddSum(ar, 6)))
# This code is contributed
# by ChitraNayal
C#
// C# code to find count
// of sub-arrays with odd sum
using System;
class GFG
{
static int countOddSum(int []ar,
int n)
{
int result = 0;
// Find sum of all subarrays
// and increment result if
// sum is odd
for (int i = 0;
i <= n - 1; i++)
{
int val = 0;
for (int j = i;
j <= n - 1; j++)
{
val = val + ar[j];
if (val % 2 != 0)
result++;
}
}
return (result);
}
// Driver code
public static void Main()
{
int []ar = {5, 4, 4, 5, 1, 3};
int n = ar.Length;
Console.Write("The Number of Subarrays" +
" with odd sum is ");
Console.WriteLine(countOddSum(ar, n));
}
}
// This code is contributed
// by chandan_jnu.
JavaScript
<script>
// Javascript code to find count of
// sub-arrays with odd sum
function countOddSum(ar, n)
{
let result = 0;
// Find sum of all subarrays
// and increment result if
// sum is odd
for(let i = 0; i <= n - 1; i++)
{
let val = 0;
for(let j = i; j <= n - 1; j++)
{
val = val + ar[j];
if (val % 2 != 0)
result++;
}
}
return (result);
}
// Driver code
let ar = [ 5, 4, 4, 5, 1, 3 ];
let n = ar.length;
document.write("The Number of Subarrays" +
" with odd sum is ");
document.write(countOddSum(ar, n));
// This code is contributed by avanitrachhadiya2155
</script>
PHP
<?php
// PHP code to find count
// of sub-arrays with odd sum
function countOddSum(&$ar, $n)
{
$result = 0;
// Find sum of all subarrays and
// increment result if sum is odd
for ($i = 0; $i <= $n - 1; $i++)
{
$val = 0;
for ($j = $i;
$j <= $n - 1; $j++)
{
$val = $val + $ar[$j];
if ($val % 2 != 0)
$result++;
}
}
return ($result);
}
// Driver code
$ar = array(5, 4, 4, 5, 1, 3);
$n = sizeof($ar);
echo "The Number of Subarrays with odd ";
echo "sum is ".countOddSum($ar, $n);
// This code is contributed
// by ChitraNayal
?>
OutputThe Number of Subarrays with odd sum is 12
Complexity Analysis:
- Time Complexity: O(n2)
- Auxiliary Space: O(1)
O(n) Time and O(1) Space Method [Efficient]: If we do compute the cumulative sum array in temp[] of our input array, then we can see that the sub-array starting from i and ending at j, has an even sum if temp[] if (temp[j] - temp[i]) % 2 = 0. So, instead of building a cumulative sum array, we build a cumulative sum modulo 2 array. Then calculating odd-even pairs will give the required result i.e. temp[0]*temp[1].
C++
// C++ program to find count of sub-arrays
// with odd sum
#include <bits/stdc++.h>
using namespace std;
int countOddSum(int ar[], int n)
{
// A temporary array of size 2. temp[0] is going to
// store count of even subarrays and temp[1] count of
// odd. temp[0] is initialized as 1 because there a
// single odd element is also counted as a subarray
int temp[2] = { 1, 0 };
// Initialize count. sum is sum of elements under modulo
// 2 and ending with arr[i].
int result = 0, val = 0;
// i'th iteration computes sum of arr[0..i] under modulo
// 2 and increments even/odd count according to sum's
// value
for (int i = 0; i <= n - 1; i++) {
// 2 is added to handle negative numbers
val = ((val + ar[i]) % 2 + 2) % 2;
// Increment even/odd count
temp[val]++;
}
// An odd can be formed by even-odd pair
result = (temp[0] * temp[1]);
return (result);
}
// Driver code
int main()
{
int ar[] = { 5, 4, 4, 5, 1, 3 };
int n = sizeof(ar) / sizeof(ar[0]);
cout << "The Number of Subarrays with odd sum is "
<< countOddSum(ar, n);
return (0);
}
// This code is contributed by Sania Kumari Gupta
C
// C++ program to find count of sub-arrays
// with odd sum
#include <stdio.h>
int countOddSum(int ar[], int n)
{
// A temporary array of size 2. temp[0] is going to
// store count of even subarrays and temp[1] count of
// odd. temp[0] is initialized as 1 because there a
// single odd element is also counted as a subarray
int temp[2] = { 1, 0 };
// Initialize count. sum is sum of elements under modulo
// 2 and ending with arr[i].
int result = 0, val = 0;
// i'th iteration computes sum of arr[0..i] under modulo
// 2 and increments even/odd count according to sum's
// value
for (int i = 0; i <= n - 1; i++) {
// 2 is added to handle negative numbers
val = ((val + ar[i]) % 2 + 2) % 2;
// Increment even/odd count
temp[val]++;
}
// An odd can be formed by even-odd pair
result = (temp[0] * temp[1]);
return (result);
}
// Driver code
int main()
{
int ar[] = { 5, 4, 4, 5, 1, 3 };
int n = sizeof(ar) / sizeof(ar[0]);
printf("The Number of Subarrays with odd sum is %d",
countOddSum(ar, n));
return (0);
}
// This code is contributed by Sania Kumari Gupta
Java
// Java code to find count of sub-arrays
// with odd sum
import java.io.*;
class GFG {
static int countOddSum(int ar[], int n)
{
// A temporary array of size 2. temp[0] is going to
// store count of even subarrays and temp[1] count
// of odd. temp[0] is initialized as 1 because there
// a single odd element is also counted as a
// subarray
int temp[] = { 1, 0 };
// Initialize count. sum is sum of elements under
// modulo 2 and ending with arr[i].
int result = 0, val = 0;
// i'th iteration computes sum of arr[0..i] under
// modulo 2 and increments even/odd count according
// to sum's value
for (int i = 0; i <= n - 1; i++) {
// 2 is added to handle negative numbers
val = ((val + ar[i]) % 2 + 2) % 2;
// Increment even/odd count
temp[val]++;
}
// An odd can be formed by an even-odd pair
result = temp[0] * temp[1];
return (result);
}
// Driver code
public static void main(String[] args)
{
int ar[] = { 5, 4, 4, 5, 1, 3 };
int n = ar.length;
System.out.println(
"The Number of Subarrays with odd sum is "
+ countOddSum(ar, n));
}
}
// This code is contributed by Sania Kumari Gupta
Python3
# Python 3 program to
# find count of sub-arrays
# with odd sum
def countOddSum(ar, n):
# A temporary array of size
# 2. temp[0] is going to
# store count of even subarrays
# and temp[1] count of odd.
# temp[0] is initialized as 1
# because there is a single odd
# element is also counted as
# a subarray
temp = [ 1, 0 ]
# Initialize count. sum is sum
# of elements under modulo 2
# and ending with arr[i].
result = 0
val = 0
# i'th iteration computes
# sum of arr[0..i] under
# modulo 2 and increments
# even/odd count according
# to sum's value
for i in range(n):
# 2 is added to handle
# negative numbers
val = ((val + ar[i]) % 2 + 2) % 2
# Increment even/odd count
temp[val] += 1
# An odd can be formed
# by even-odd pair
result = (temp[0] * temp[1])
return (result)
# Driver code
ar = [ 5, 4, 4, 5, 1, 3 ]
print("The Number of Subarrays"
" with odd sum is "+
str(countOddSum(ar, 6)))
# This code is contributed
# by ChitraNayal
C#
// C# code to find count of
// sub-arrays with odd sum
using System;
class GFG
{
static int countOddSum(int[] ar,
int n)
{
// A temporary array of size 2.
// temp[0] is going to store
// count of even subarrays
// and temp[1] count of odd.
// temp[0] is initialized as
// 1 because there a single odd
// element is also counted as
// a subarray
int[] temp = { 1, 0 };
// Initialize count. sum is
// sum of elements under modulo
// 2 and ending with arr[i].
int result = 0, val = 0;
// i'th iteration computes sum
// of arr[0..i] under modulo 2
// and increments even/odd count
// according to sum's value
for (int i = 0; i <= n - 1; i++)
{
// 2 is added to handle
// negative numbers
val = ((val + ar[i]) % 2 + 2) % 2;
// Increment even/odd count
temp[val]++;
}
// An odd can be formed
// by an even-odd pair
result = temp[0] * temp[1];
return (result);
}
// Driver code
public static void Main()
{
int[] ar = { 5, 4, 4, 5, 1, 3 };
int n = ar.Length;
Console.Write("The Number of Subarrays" +
" with odd sum is " +
countOddSum(ar, n));
}
}
// This code is contributed
// by ChitraNayal
JavaScript
<script>
// Javascript code to find count of
// sub-arrays with odd sum
function countOddSum(ar, n)
{
// A temporary array of size 2.
// temp[0] is going to store
// count of even subarrays
// and temp[1] count of odd.
// temp[0] is initialized as
// 1 because there a single odd
// element is also counted as
// a subarray
let temp = [1, 0];
// Initialize count. sum is
// sum of elements under modulo
// 2 and ending with arr[i].
let result = 0, val = 0;
// i'th iteration computes sum
// of arr[0..i] under modulo 2
// and increments even/odd count
// according to sum's value
for(let i = 0; i <= n - 1; i++)
{
// 2 is added to handle
// negative numbers
val = ((val + ar[i]) % 2 + 2) % 2;
// Increment even/odd count
temp[val]++;
}
// An odd can be formed
// by an even-odd pair
result = temp[0] * temp[1];
return (result);
}
// Driver code
let ar = [ 5, 4, 4, 5, 1, 3 ];
let n = ar.length;
document.write("The Number of Subarrays" +
" with odd sum is " +
countOddSum(ar, n));
// This code is contributed by rameshtravel07
</script>
PHP
<?php
// PHP program to find count
// of sub-arrays with odd sum
function countOddSum($ar, $n)
{
// A temporary array of size
// 2. temp[0] is going to
// store count of even subarrays
// and temp[1] count of odd.
// temp[0] is initialized as 1
// because there is a single odd
// element is also counted as
// a subarray
$temp = array(1, 0);
// Initialize count. sum is
// sum of elements under
// modulo 2 and ending with arr[i].
$result = 0;
$val = 0;
// i'th iteration computes sum
// of arr[0..i] under modulo 2
// and increments even/odd count
// according to sum's value
for ($i = 0; $i <= $n - 1; $i++)
{
// 2 is added to handle
// negative numbers
$val = (($val + $ar[$i]) %
2 + 2) % 2;
// Increment even/odd count
$temp[$val]++;
}
// An odd can be formed
// by even-odd pair
$result = ($temp[0] * $temp[1]);
return ($result);
}
// Driver code
$ar = array(5, 4, 4, 5, 1, 3);
$n = sizeof($ar);
echo "The Number of Subarrays with odd".
" sum is ".countOddSum($ar, $n);
// This code is contributed
// by ChitraNayal
?>
OutputThe Number of Subarrays with odd sum is 12
Complexity Analysis:
- Time Complexity: O(n)
- Auxiliary Space: O(1)
Another efficient approach is to first find the number of subarrays starting at index 0 and having an odd sum. Then traverse the array and update the number of subarrays starting at index i and having an odd sum.
Implementation:
C++
// C++ program to find number of subarrays with odd sum
#include <bits/stdc++.h>
using namespace std;
// Function to find number of subarrays with odd sum
int countOddSum(int a[], int n)
{
// 'odd' stores number of odd numbers upto ith index
// 'c_odd' stores number of odd sum subarrays starting
// at ith index
//'Result' stores the number of odd sum subarrays
int odd = 0, c_odd = 0, result = 0;
// First find number of odd sum subarrays starting at
// 0th index
for (int i = 0; i < n; i++) {
if (a[i] & 1)
odd = !odd;
if (odd)
c_odd++;
}
// Find number of odd sum subarrays starting at ith
// index add to result
for (int i = 0; i < n; i++) {
result += c_odd;
if (a[i] & 1)
c_odd = (n - i - c_odd);
}
return result;
}
// Driver code
int main()
{
int ar[] = { 5, 4, 4, 5, 1, 3 };
int n = sizeof(ar) / sizeof(ar[0]);
cout << "The Number of Subarrays with odd sum is "
<< countOddSum(ar, n);
return (0);
}
// This code is contributed by Sania Kumari Gupta
C
// C++ program to find number of subarrays with odd sum
#include <stdio.h>
// Function to find number of subarrays with odd sum
int countOddSum(int a[], int n)
{
// 'odd' stores number of odd numbers upto ith index
// 'c_odd' stores number of odd sum subarrays starting
// at ith index
//'Result' stores the number of odd sum subarrays
int odd = 0, c_odd = 0, result = 0;
// First find number of odd sum subarrays starting at
// 0th index
for (int i = 0; i < n; i++) {
if (a[i] & 1)
odd = !odd;
if (odd)
c_odd++;
}
// Find number of odd sum subarrays starting at ith
// index add to result
for (int i = 0; i < n; i++) {
result += c_odd;
if (a[i] & 1)
c_odd = (n - i - c_odd);
}
return result;
}
// Driver code
int main()
{
int ar[] = { 5, 4, 4, 5, 1, 3 };
int n = sizeof(ar) / sizeof(ar[0]);
printf("The Number of Subarrays with odd sum is %d",
countOddSum(ar, n));
return (0);
}
// This code is contributed by Sania Kumari Gupta
Java
// Java program to find number of subarrays
// with odd sum
import java.util.*;
class GFG {
// Function to find number of subarrays with odd sum
static int countOddSum(int a[], int n)
{
// 'odd' stores number of odd numbers upto ith index
// 'c_odd' stores number of odd sum subarrays starting at ith index
//'Result' stores the number of odd sum subarrays
int c_odd = 0, result = 0;
boolean odd = false;
// First find number of odd sum subarrays starting
// at 0th index
for (int i = 0; i < n; i++) {
if (a[i] % 2 == 1)
odd = !odd;
if (odd)
c_odd++;
}
// Find number of odd sum subarrays starting at ith
// index add to result
for (int i = 0; i < n; i++) {
result += c_odd;
if (a[i] % 2 == 1)
c_odd = (n - i - c_odd);
}
return result;
}
// Driver code
public static void main(String[] args)
{
int ar[] = { 5, 4, 4, 5, 1, 3 };
int n = ar.length;
System.out.print(
"The Number of Subarrays with odd sum is "
+ countOddSum(ar, n));
}
}
// This code is contributed by Sania Kumari Gupta
Python3
# Python3 program to find
# number of subarrays with
# odd sum
# Function to find number
# of subarrays with odd sum
def countOddSum(a, n):
# 'odd' stores number of
# odd numbers upto ith index
# 'c_odd' stores number of
# odd sum subarrays starting
# at ith index
# 'Result' stores the number
# of odd sum subarrays
c_odd = 0;
result = 0;
odd = False;
# First find number of odd
# sum subarrays starting at
# 0th index
for i in range(n):
if (a[i] % 2 == 1):
if(odd == True):
odd = False;
else:
odd = True;
if (odd):
c_odd += 1;
# Find number of odd sum
# subarrays starting at ith
# index add to result
for i in range(n):
result += c_odd;
if (a[i] % 2 == 1):
c_odd = (n - i - c_odd);
return result;
# Driver code
if __name__ == '__main__':
ar = [5, 4, 4, 5, 1, 3];
n = len(ar);
print("The Number of Subarrays" +
"with odd sum is " ,
countOddSum(ar, n));
# This code is contributed by shikhasingrajput
C#
// C# program to find number of subarrays
// with odd sum
using System;
public class GFG{
// Function to find number of
// subarrays with odd sum
static int countOddSum(int []a, int n)
{
// 'odd' stores number of odd numbers
// upto ith index
// 'c_odd' stores number of odd sum
// subarrays starting at ith index
// 'Result' stores the number of
// odd sum subarrays
int c_odd = 0, result = 0;
bool odd = false;
// First find number of odd sum
// subarrays starting at 0th index
for(int i = 0; i < n; i++)
{
if (a[i] % 2 == 1)
{
odd = !odd;
}
if (odd)
{
c_odd++;
}
}
// Find number of odd sum subarrays
// starting at ith index add to result
for(int i = 0; i < n; i++)
{
result += c_odd;
if (a[i] % 2 == 1)
{
c_odd = (n - i - c_odd);
}
}
return result;
}
// Driver code
public static void Main(String[] args)
{
int []ar = { 5, 4, 4, 5, 1, 3 };
int n = ar.Length;
Console.Write("The Number of Subarrays " +
"with odd sum is " +
countOddSum(ar, n));
}
}
// This code is contributed by 29AjayKumar
JavaScript
<script>
// JavaScript program to find number
// of subarrays with odd sum
// Function to find number of
// subarrays with odd sum
function countOddSum(a, n)
{
// 'odd' stores number of odd numbers
// upto ith index
// 'c_odd' stores number of odd sum
// subarrays starting at ith index
// 'Result' stores the number of
// odd sum subarrays
let c_odd = 0, result = 0;
let odd = false;
// First find number of odd sum
// subarrays starting at 0th index
for(let i = 0; i < n; i++)
{
if (a[i] % 2 == 1)
{
odd = !odd;
}
if (odd)
{
c_odd++;
}
}
// Find number of odd sum subarrays
// starting at ith index add to result
for(let i = 0; i < n; i++)
{
result += c_odd;
if (a[i] % 2 == 1)
{
c_odd = (n - i - c_odd);
}
}
return result;
}
let ar = [ 5, 4, 4, 5, 1, 3 ];
let n = ar.length;
document.write("The Number of Subarrays " +
"with odd sum is " +
countOddSum(ar, n));
</script>
OutputThe Number of Subarrays with odd sum is 12
Complexity Analysis:
- Time Complexity: O(n)
- Auxiliary Space: O(1)
Similar Reads
Number of Subsequences with Even and Odd Sum
Given an array, find the number of subsequences whose sum is even and the number of subsequences whose sum is odd. Example: Input: arr[] = {1, 2, 2, 3} Output: EvenSum = 7, OddSum = 8 There are 2^{N}-1 possible subsequences. The subsequences with even sum is 1) {1, 3} Sum = 4 2) {1, 2, 2, 3} Sum = 8
15 min read
Count of sub-arrays with odd product
Given an integer array arr[] of size N, the task is to count the number of sub-arrays that have an odd product.Examples: Input : arr[] = {5, 1, 2, 3, 4} Output : 4 Explanation: The sub-arrays with odd product are- {5}, {1}, {3}, {5, 1}. Hence the count is 4.Input : arr[] = {12, 15, 7, 3, 25, 6, 2, 1
7 min read
Subarrays with k odd numbers
Given an integer array arr[] of size n, and an integer k. Your task is to find the number of contiguous subarrays in the array arr[], which contains exactly k odd numbers.Examples : Input : arr = [2, 5, 6, 9], k = 2 Output: 2Explanation: There are 2 subarrays with 2 odds: [2, 5, 6, 9] and [5, 6, 9].
15+ min read
Number of Subsequences with Even and Odd Sum | Set 2
Given an array arr[] of size N. The task is to find the number of subsequences whose sum is even and the number of subsequences whose sum is odd.Examples: Input: arr[] = {1, 2, 2, 3} Output: EvenSum = 7, OddSum = 8 There are 2N-1 possible subsequences. The subsequences with even sum are 1) {1, 3} Su
7 min read
Find number of subarrays with even sum
Given an array, find the number of subarrays whose sum is even. Example : Input : arr[] = {1, 2, 2, 3, 4, 1} Output : 9 There are possible subarrays with even sum. The subarrays are 1) {1, 2, 2, 3} Sum = 8 2) {1, 2, 2, 3, 4} Sum = 12 3) {2} Sum = 2 (At index 1) 4) {2, 2} Sum = 4 5) {2, 2, 3, 4, 1} S
15+ min read
Count of triplets in an Array with odd sum
Given an array arr[] with N integers, find the number of triplets of i, j and k such that 1<= i < j < k <= N and arr[i] + arr[j] + arr[k] is odd. Example: Input: arr[] = {1, 2, 3, 4, 5}Output: 4Explanation: The given array contains 4 triplets with an odd sum. They are {1, 2, 4}, {1, 3, 5
6 min read
Number of subsequences with zero sum
Given an array arr[] of N integers. The task is to count the number of sub-sequences whose sum is 0. Examples: Input: arr[] = {-1, 2, -2, 1} Output: 3 All possible sub-sequences are {-1, 1}, {2, -2} and {-1, 2, -2, 1} Input: arr[] = {-2, -4, -1, 6, -2} Output: 2 Approach: The problem can be solved u
6 min read
Subsequence with maximum odd sum
Given a set of integers, check whether there is a subsequence with odd sum and if yes, then finding the maximum odd sum. If no subsequence contains odd sum, return -1. Examples : Input : arr[] = {2, 5, -4, 3, -1}; Output : 9 The subsequence with maximum odd sum is 2, 5, 3 and -1. Input : arr[] = {4,
9 min read
Split the array into odd number of segments of odd lengths
Given an array of n length. The task is to check if the given array can be split into an odd number of sub-segment starting with odd integer and also the length of sub-segment must be odd. If possible the print â1â else print â0â.Examples:Input: arr[] = {1, 3, 1}Output: 11, 3, 1, can be split into 3
7 min read
Number of pairs with Bitwise OR as Odd number
Given an array A[] of size N. The task is to find how many pair(i, j) exists such that A[i] OR A[j] is odd.Examples: Input : N = 4 A[] = { 5, 6, 2, 8 } Output : 3 Explanation : Since pair of A[] = ( 5, 6 ), ( 5, 2 ), ( 5, 8 ), ( 6, 2 ), ( 6, 8 ), ( 2, 8 ) 5 OR 6 = 7, 5 OR 2 = 7, 5 OR 8 = 13 6 OR 2 =
9 min read