Tap here to switch tabs
Problem
Submissions

Problem: Longest Subarray With Restricted Pair Sums

med
30 min
Try to solve the Longest Subarray With Restricted Pair Sums problem.

Statement

Given an integer array nums, find the length of the longest contiguous subarray such that no element in the subarray is equal to the sum of two other elements at distinct indices within that subarray.

More formally, a subarray is valid if there are no three pairwise distinct indices ii, jj, and kk within the subarray such that subarray[i] + subarray[j] = subarray[k].

Return the maximum length of a valid subarray.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤500\leq 500

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Subarray With Restricted Pair Sums

med
30 min
Try to solve the Longest Subarray With Restricted Pair Sums problem.

Statement

Given an integer array nums, find the length of the longest contiguous subarray such that no element in the subarray is equal to the sum of two other elements at distinct indices within that subarray.

More formally, a subarray is valid if there are no three pairwise distinct indices ii, jj, and kk within the subarray such that subarray[i] + subarray[j] = subarray[k].

Return the maximum length of a valid subarray.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤500\leq 500