Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

PayPal interview question

Count contiguous subarrays whose elements sum to a target value

Company:
PayPal
Type:
Coding
Difficulty:
Medium
Reported:
October 4, 2026

Problem

Given an integer array nums and an integer k, return the number of contiguous, non-empty subarrays whose elements add up to exactly k. The array may contain negative numbers and zeros, and subarrays at different positions are counted separately even if they contain the same values.

Example 1

Input: nums = [1, 1, 1], k = 2
Output: 2

The subarrays [1, 1] at positions 0-1 and 1-2.

Example 2

Input: nums = [1, -1, 0], k = 0
Output: 3

The subarrays [1, -1], [0] and [1, -1, 0].

Constraints

  • 1 <= len(nums) <= 2 * 10^4
  • -1000 <= nums[i] <= 1000
  • -10^7 <= k <= 10^7

Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern