Count Special Quadruplets

Given a 0-indexed integer array nums, return the number of distinct quadruplets (a, b, c, d) such that:

  • nums[a] + nums[b] + nums[c] == nums[d], and
  • a < b < c < d
Example 1
Inputnums = [1,2,3,6]
Output1
The only quadruplet that satisfies the requirement is (0, 1, 2, 3) because 1 + 2 + 3 == 6.
Example 2
Inputnums = [3,3,6,4,5]
Output0
There are no such quadruplets in [3, 3, 6, 4, 5].

Constraints

  • 4 <= nums.length <= 50
  • 1 <= nums[i] <= 100

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate