res to 0 to store the number of quadruplets found.count to store the frequency of differences nums[d] - nums[c].b.b, iterate over all elements before it, treating them as a, and add to res the frequency of nums[a] + nums[b] found in count.a for a given b, iterate over all elements after b, treating them as d, and update the map count with the new differences nums[d] - nums[b].res as the final result.