This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
#define ll long long | |
public: | |
long long countSubarrays(vector<int>& nums, int minK, int maxK) { | |
ll valid_subarrays = 0; | |
int invalid_idx = -1; | |
int minK_idx = -1; | |
int maxK_idx = -1; | |
for(int i=0;i<nums.size();++i){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
using ll = long long; | |
public: | |
long long countSubarrays(const vector<int>& nums, long long k) { | |
ll n = nums.size(); | |
ll left = 0, right = 0; // window is [left, right) | |
ll sum = 0; // sum of nums[left..right-1] | |
ll count = 0; | |
while (left < n) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
#define ll long long | |
public: | |
long long countInterestingSubarrays(vector<int>& nums, int modulo, int k) { | |
ll n = nums.size(); | |
ll pos=0; | |
ll interesting_subarrays = 0; | |
ll prefix_count = 0; | |
unordered_map<ll,ll> mod_freq; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int countCompleteSubarrays(vector<int>& nums) { | |
unordered_set<int> unique_elements(nums.begin(),nums.end()); | |
int unique_count = unique_elements.size(); | |
int left = 0; | |
int right = 0; | |
int n = nums.size(); | |
unordered_map<int,int> freq; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
vector<int> findLPS(string& patt){ | |
int n=patt.size(); | |
vector<int> lps(n); | |
int i=1; | |
int j=0; | |
while(i<n){ | |
if(patt[i]==patt[j]){ | |
lps[i]=j+1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
#define ll long long | |
ll count[15][10005]; | |
ll prefix_sum[15][10005]; | |
ll options[15]; | |
int MOD = 1e9+7; | |
void countUniqueSequences(int curr,int idx,int& maxValue){ | |
options[idx]+=1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int numRabbits(vector<int>& answers) { | |
int n = answers.size(); | |
unordered_map<int,int> group_freq; | |
int count = 0; | |
//Insert all elements and count full_group_elements | |
for(int ele: answers){ | |
if(ele==0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
string countAndSay(int n) { | |
if(n==1) return "1"; | |
string number = "1"; | |
for(int i=2;i<=n;++i){ | |
//Build new string | |
string res; | |
int count = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
using ll = long long; | |
public: | |
long long countGood(vector<int>& nums, int k) { | |
ll n = nums.size(); | |
ll left = 0, right = 0; | |
ll good_subarrays = 0; | |
unordered_map<ll,ll> freq; | |
ll equal_pairs = 0; |
NewerOlder