Skip to main content
LeetCode 548, Hard. Topics: Array, Hash Table, Prefix Sum. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:

Problem

Given an integer array nums of length n, return true if there is a triplet (i, j, k) which satisfies the following conditions:
  • 0 < i, i + 1 < j, j + 1 < k < n - 1
  • The sum of subarrays (0, i - 1), (i + 1, j - 1), (j + 1, k - 1) and (k + 1, n - 1) is equal.
A subarray (l, r) represents a slice of the original array starting from the element indexed l to the element indexed r.

Examples

Constraints

  • n == nums.length
  • 1 <= n <= 2000
  • -10^6 <= nums[i] <= 10^6

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026