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 { | |
int tryRotationMatching(int number,vector<int>& first,vector<int>& second){ | |
int count = 0; | |
for(int i=0;i<first.size();++i){ | |
if(first[i]==number) continue; | |
else if(second[i]==number) count++; | |
else return INT_MAX; | |
} | |
return count; | |
} |
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 Domino { | |
public: | |
void doubleDominoPush(int last_R, int pos, string& dominoes) { | |
while (last_R < pos) { | |
dominoes[last_R++] = 'R'; | |
dominoes[pos--] = 'L'; | |
} | |
} | |
void leftDominoPush(int start, int end, string& dominoes) { |
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 { | |
bool canAssign(int mid,vector<int>& workers,vector<int>& tasks,int pills,int strength){ | |
multiset<int> usable_workers(workers.end()-mid,workers.end()); | |
for(int i=mid-1;i>=0;--i){ | |
auto curr_worker = --usable_workers.end(); | |
if(*curr_worker < tasks[i]){ | |
if(pills<=0) return false; | |
//Optimal Strategy: Assign weakest worker to get the current task done |
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; |
NewerOlder