Asked inDunzo,SDE-2

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 size N.
  • 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!
Select
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
Dunzo SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits