Number of Subsequences with Even and Odd Sum
Your task is to determine the number of subsequences with odd sums and the number of subsequences with even sums from a given array of positive integers. As resulting numbers can be large, return both counts modulo 109 + 7.
Definition:
- An even sum subsequence is one where the total sum of elements is divisible by 2.
- An odd sum subsequence is one where the total sum leaves a remainder of 1 when divided by 2.
Example:
Input:
T = 1
N = 3
array = [1, 2, 3]
Output:
3 4
Explanation:
The possible non-empty subsequences are {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}. Out of these, the odd sum subsequences are {1}, {3}, {2,3}, {1,2,3} and the even sum ones are {2}, {1,2}, {1,3}.
Constraints:
1 <= T <= 100
1 <= N <= 104
1 <= ARR[i] <= 109
Note:
- There are
2N - 1
non-empty subsequences for an array of sizeN
. - Subsequences can contain duplicate elements from the array.
- The modulo operation 109 + 7 ensures the numbers remain manageable.
- The function that you implement does not need to handle I/O operations.

AnswerBot
4mo
Count the number of subsequences with odd and even sums in a given array of positive integers modulo 10^9 + 7.
Use dynamic programming to keep track of the count of subsequences with odd and even sums....read more
Help your peers!
Add answer anonymously...
Dunzo SDE-2 interview questions & answers
A SDE-2 was asked Q. Container with Most Water Problem Statement Given a sequence of 'N' space-separa...read more
A SDE-2 was asked Q. Maximum Size Rectangle Binary Sub-Matrix with All 1s Given a binary-valued matri...read more
A SDE-2 was asked Q. Number of Subsequences with Even and Odd Sum Your task is to determine the numbe...read more
Popular interview questions of SDE-2
A SDE-2 was asked Q1. Container with Most Water Problem Statement Given a sequence of 'N' space-separa...read more
A SDE-2 was asked Q2. Maximum Size Rectangle Binary Sub-Matrix with All 1s Given a binary-valued matri...read more
A SDE-2 was asked Q3. Number of Subsequences with Even and Odd Sum Your task is to determine the numbe...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

