Count Inclusive-Band Sums of Nonempty Index Ranges

Quick Overview

Count Inclusive-Band Sums of Nonempty Index Ranges. Return the number of nonempty contiguous ranges whose sum lies between lower and upper inclusive. Count index ranges separately even when their sums are equal.

Count Inclusive-Band Sums of Nonempty Index Ranges

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Return the number of nonempty contiguous ranges whose sum lies between lower and upper inclusive. Count index ranges separately even when their sums are equal. ```cpp int countRangeSum(vector<int>& nums, int lower, int upper); ``` ### Examples ```text nums = [1,-1,2], lower=0, upper=1 -> 3 nums = [0], lower=0, upper=0 -> 1 ``` ### Constraints - Length is 1 through 100000; values span signed 32-bit. - -100000 <= lower <= upper <= 100000. - The final count is guaranteed to fit signed 32-bit.

Overview: Count Inclusive-Band Sums of Nonempty Index Ranges. Return the number of nonempty contiguous ranges whose sum lies between lower and upper inclusive. Count index ranges separately even when their sums are equal.

Amazon logo
Amazon
Date not reported
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return the number of nonempty contiguous ranges whose sum lies between lower and upper inclusive. Count index ranges separately even when their sums are equal.

int countRangeSum(vector<int>& nums, int lower, int upper);

Examples

nums = [1,-1,2], lower=0, upper=1 -> 3
nums = [0], lower=0, upper=0 -> 1

Constraints

  • Length is 1 through 100000; values span signed 32-bit.
  • -100000 <= lower <= upper <= 100000.
  • The final count is guaranteed to fit signed 32-bit.