diff --git a/2381. Shifting Letters II b/2381. Shifting Letters II new file mode 100644 index 0000000..455fb9c --- /dev/null +++ b/2381. Shifting Letters II @@ -0,0 +1,40 @@ +class Solution { +public: + string shiftingLetters(string s, vector>& shifts) { + int n=s.length(); + vector count(n+1,0); + for(auto it:shifts){ + int l=it[0]; + int r=it[1]; + int dir=it[2]; + if(dir == 1){ + count[l]+=1; + count[r+1]-=1; + }else{ + count[l]-=1; + count[r+1]+=1; + } + } + //for(int i=0;i<=n;i++) cout< pref(n+1,0); + pref[0]=count[0]; + for(int i=1;i<=n;i++){ + pref[i]=count[i]+pref[i-1]; + } + //cout<