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: | |
bool isZeroArray(vector<int>& nums, vector<vector<int>>& queries) { | |
int n=nums.size(); | |
vector<int> diff(n+1,0); | |
for(auto& query: queries){ | |
int start = query[0]; | |
int end = query[1]; | |
diff[start]++; | |
diff[end+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 { | |
/* | |
No of rows = 1000 maximum | |
Colors per cell = 3 | |
Color Combinations used: | |
00: No color (White) | |
01: Red | |
10: Green | |
11: Blue | |
Cell per column = No of rows = 5 |
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 hammingDistance(const string &a, const string &b) { | |
int hamming_distance = 0; | |
for (int i = 0, n = a.size(); i < n; ++i) | |
if (a[i] != b[i]) | |
++hamming_distance; | |
return hamming_distance; | |
} | |
public: |
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 Matrix = array<array<int,26>,26>; | |
int MOD = 1e9+7; | |
inline Matrix matrixMultiplication(Matrix& A,Matrix& B){ | |
Matrix res{}; | |
for(int i=0;i<26;++i){ | |
for(int j=0;j<26;++j){ | |
for(int k=0;k<26;++k){ | |
res[i][j] = (res[i][j] + (1LL*A[i][k]*B[k][j]) % MOD) % MOD; |
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 MOD = 1e9+7; | |
inline int modAdd(int a,int b){ | |
return ((a % MOD)+(b % MOD))% MOD; | |
} | |
public: | |
int lengthAfterTransformations(string s, int t) { | |
array<int,26> sfreq{}; | |
for(char c: s) | |
sfreq[c-'a']++; |
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; | |
void calculate(ll& min_sum,int& zero_count,vector<int>& nums){ | |
for(int ele: nums){ | |
if(ele==0){ | |
zero_count++; | |
min_sum++; | |
}else | |
min_sum += ele; |
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; | |
int mod=1e9+7; | |
int tot_ways_to_permute; | |
vector<int> fact; | |
vector<int> inverse_fact; | |
vector<int> freq; | |
int mem[10][40+2][42*9];//Digits:[0,9]...Length:[2,80]...MaxSumOfDigits:[80*9] |
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
//Approach-1: Simple Recursion + Memoization | |
class Solution { | |
int dp[1005][1005]; | |
int MOD = 1e9+7; | |
int countTilingWays(int r1,int r2){ | |
if(r1==0 and r2==0) return 1;//Valid tiling completed | |
if(r1<=0 or r2<=0) return 0;//Invalid tiling | |
if(dp[r1][r2]!=-1) return dp[r1][r2]; | |
long long count = 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 { | |
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) { |
NewerOlder