FastPrepLongest Zero Sum Subarray
Problems/Longest Zero Sum Subarray

Longest Zero Sum Subarray

Amazon logoAmazonFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an integer array nums containing positive and negative integers.

Return the length of the longest contiguous subarray whose sum is equal to 0. If no such subarray exists, return 0.

Function

longestZeroSumSubarray(nums: int[]) → int

Examples

Example 1

nums = [15, -2, 2, -8, 1, 7, 10, 23]return = 5

The subarray [-2, 2, -8, 1, 7] has sum 0 and length 5.

Example 2

nums = [1, 2, 3]return = 0

No non-empty contiguous subarray has sum 0.

Constraints

  • 1 <= nums.length
  • nums[i] may be positive, negative, or zero.

Source note: Source images are source-neutral excerpts of author-reported interview prompts.

More Amazon Onsite Interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Optimal Account BalancingONSITE INTERVIEW · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int longestZeroSumSubarray(int[] nums) {
      // write your code here
    }
}
Checking account…