From 02e2af75c00a74e949cbac05c900210a79dca509 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Sat, 14 Dec 2024 18:30:37 +0530 Subject: [PATCH] Create 2762. Continuous Subarrays --- 2762. Continuous Subarrays | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 2762. Continuous Subarrays diff --git a/2762. Continuous Subarrays b/2762. Continuous Subarrays new file mode 100644 index 0000000..7301368 --- /dev/null +++ b/2762. Continuous Subarrays @@ -0,0 +1,22 @@ +class Solution { +public: + long long continuousSubarrays(vector& nums) { + map mp; + int left,right=0; + int n=nums.size(); + long long cnt=0; + while(rightfirst-mp.begin()->first>2){ + mp[nums[left]]--; + if(mp[nums[left]]==0){ + mp.erase(nums[left]); + } + left++; + } + cnt+=right-left+1; + right++; + } + return cnt; + } +};