Subarrays Whose Sum Is a Power of Two
Problem statement
Return every zero-based inclusive interval [left, right] whose contiguous-subarray sum is a positive power of two.
Order the intervals by increasing left, then increasing right. Negative values may appear.
Function
powerOfTwoSubarrays(nums: int[]) → int[][]Examples
Example 1
nums = [1,1,3]return = [[0,0],[0,1],[1,1],[1,2]]The qualifying interval sums are 1, 2, 1, and 4.
Example 2
nums = [-1,3]return = [[0,1]]The full subarray sums to 2.
Constraints
0 <= nums.length <= 2000.-10^9 <= nums[i] <= 10^9.
Source note: Author-written prompt excerpt retained for source fidelity.