Skip to content
Onsite

K Odd Subset II

MediumP3Coding

Given an array nums of positive integers and an integer k, return the number of non-empty subsets of the array that contain exactly k odd numbers.

A subset is a choice of positions: elements with equal values at different indices count as different elements.

Example 1

Input
nums = [1,2,3], k = 2
Output
2

Example 2

Input
nums = [2,4,6], k = 0
Output
7

Example 3

Input
nums = [1,3,5], k = 0
Output
0

Constraints

  • 1 <= nums.length <= 30
  • 1 <= nums[i] <= 10^9
  • 0 <= k <= nums.length

Hints

Run checks the 3 visible tests, Submit all 10.