Count Special Triplets

You are given an integer array nums.

A special triplet is defined as a triplet of indices (i, j, k) such that:

  • 0 <= i < j < k < n, where n = nums.length
  • nums[i] == nums[j] * 2
  • nums[k] == nums[j] * 2

Return the total number of special triplets in the array.

Since the answer may be large, return it modulo 10^9 + 7.

Example 1
Inputnums = [6,3,6]
Output1
The only special triplet is (i, j, k) = (0, 1, 2), where nums[0] = nums[1] * 2 = nums[2] = 6.
Example 2
Inputnums = [0,1,0,0]
Output1
The only special triplet is (i, j, k) = (0, 2, 3), where all three values are 0 and 0 = 0 * 2.

Constraints

  • 3 <= n == nums.length <= 10^5
  • 0 <= nums[i] <= 10^5

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