Even numbers will only create even numbers when added up.
Odd numbers will create even numbers when even numbers of odd numbers are added up.

So, given a sequence, the number of sub-sequence with odd sum would be:

(all possible sub-sequence with only even numbers) * (sub-sequence of odd-length with only odd numbers)

Now for finding all possible sub-sequence with only even numbers, we can use the formula 2 ^ number_even_numbers

Now for finding all possible odd-length sub-sequence with only odd numbers, we can use the formula 2 ^ (number_odd_numbers - 1) if we have odd numbers, else the count would be zero.

So, when there is odd numbers,

~ (all possible sub-sequence with only even numbers) * (sub-sequence of odd-length with only odd numbers)

~ 2 ^ number_even_numbers * (2 ^ (number_odd_numbers - 1))

~ 2 ^ (total_numbers - 1) as number_even_numbers + number_odd_numbers - 1 == total_numbers -1

Except, when there is no odd_numbers,

~ (all possible sub-sequence with only even numbers) * (sub-sequence of odd-length with only odd numbers)

~ 2 ^ number_even_numbers * 0

~ 0

Statistics

70% Solution Ratio
Carmel.338175Earliest, Nov '21
Kuddus.6068Fastest, 0.0s
mobarak_aiubLightest, 1.5 MB
ChAseRShortest, 443B
Toph uses cookies. By continuing you agree to our Cookie Policy.