FastPrepSubarrays Whose Sum Is a Power of Two

Subarrays Whose Sum Is a Power of Two

Kotak Mahindra Bank logoKotak Mahindra Bank● MediumFULLTIMEONSITE INTERVIEW
Learn

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.

More Kotak Mahindra Bank problems

See Kotak Mahindra Bank hiring insights
public int[][] powerOfTwoSubarrays(int[] nums) {
    // Write your code here.
}
nums[1,1,3]
expected[[0,0],[0,1],[1,1],[1,2]]
Checking account…