# Leetcode 1995 - Count Special Quadruplets

Note:

• Use brute force with $O(n^4)$ .
• Or iterate backwards for c while checking count[a + b + c] is 0 or not. If yes, add the count to ans. Add every c to count[c] cuz those are our ds for later uses.

Question:

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:

Code:

$O(n^3)$

$O(n^4)$