Contiguous Subset

  • 0

    Given an array and integer m, check how many unique contiguous subsets exist in the array such that each subset has m odd numbers.
    Ex1: [2,5,6,9] m=1
    [2,5], [5,6], [2,5,6],[5],[6,9],[9] are the possible subsets with m=1 odd numbers.
    Result: 6

    Ex2: [2,5,6,9] m=2
    [2,5,6,9] and [5,6,9]

    What is better than a O(n2) solution. Can it be done with backtracking(is it needed)?

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.