From 5b26d4e92996be1c8e7cb8afbc899dd54588d275 Mon Sep 17 00:00:00 2001 From: chayan das Date: Tue, 9 Dec 2025 14:33:05 +0530 Subject: [PATCH] Create 3583. Count Special Triplets --- 3583. Count Special Triplets | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 3583. Count Special Triplets diff --git a/3583. Count Special Triplets b/3583. Count Special Triplets new file mode 100644 index 0000000..edf625c --- /dev/null +++ b/3583. Count Special Triplets @@ -0,0 +1,18 @@ +class Solution { +public: + int specialTriplets(vector& nums) { + const int n = 100001, mod = 1000000007; + long ans = 0; + int hash[n], prev[n]; + for(int i = 0; i < n; i++) hash[i] = prev[i] = 0; + for(int i = 0; i < nums.size(); i++) hash[nums[i]]++; + for(int i = 1; i < nums.size() - 1; i++) { + prev[nums[i - 1]]++; + int j = nums[i], k = 2*j; + if(k < n) { + ans += (long)prev[k] * (hash[k] - prev[k] - (j == 0)); + } + } + return ans % mod; + } +};