Sub array that produces a given sum and product

后端 未结 4 1564
执念已碎
执念已碎 2021-01-14 13:48

Given an array of length N. How will you find the minimum length contiguous sub-array of whose sum is S and whose product is P. For eg 5 6 1 4 6 2 9 7 fo

4条回答
  •  抹茶落季
    2021-01-14 14:00

    You can use a hashmap to find the answer for product in O(N) time with extra space.

提交回复
热议问题