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 doesAliceWin(string s) { | |
for(int i=0;i<s.size();++i) | |
if(s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u') | |
return true; | |
return false; | |
} | |
}; | |
/* |
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 pci pair<char,int> | |
int isVowel(const char& c){ | |
return (c=='A' or c=='a' or c=='E' or c=='e' or c=='I' or c=='i' or c=='O' or c=='o' or c=='U' or c=='u'); | |
} | |
public: | |
string sortVowels(string s) { | |
int n=s.size(); | |
// Step-1: Count vowel frequency |
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 cantTalk(const unordered_set<int>& s1, const unordered_set<int>& s2) { | |
for (int lang1 : s1) | |
if (s2.count(lang1)) return false; | |
return true; | |
} | |
public: | |
int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) { | |
int m = languages.size(); | |
// STEP-1: person -> languages (1-based indexing for persons) |
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
// C++: DP Tabulation | |
class Solution { | |
public: | |
int peopleAwareOfSecret(int n, int delay, int forget) { | |
int MOD = 1e9+7; | |
vector<int> dp(n+1); | |
dp[1] = 1; | |
int win_count = 0; | |
for(int curr=2;curr<=n;++curr){ | |
if(curr-delay > 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: | |
vector<int> getNoZeroIntegers(int n) { | |
int a = 0; | |
int b = 0; | |
int power = 1; | |
while(n){ | |
int digit = n%10; | |
if(digit==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: | |
int numberOfPairs(vector<vector<int>>& points) { | |
int n = points.size(); | |
sort(points.begin(),points.end(),[](const vector<int>& p1,const vector<int>& p2){ | |
return p1[0]==p2[0] ? p1[1]>p2[1] : p1[0]<p2[0]; | |
}); | |
int count = 0; | |
for(int A=0;A<n-1;++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 { | |
public: | |
int numberOfPairs(vector<vector<int>>& points) { | |
int n = points.size(); | |
sort(points.begin(),points.end(),[](const vector<int>& p1,const vector<int>& p2){ | |
return p1[0]==p2[0] ? p1[1]>p2[1] : p1[0]<p2[0]; | |
}); | |
int count = 0; | |
for(int A=0;A<n-1;++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 { | |
#define ll long long | |
public: | |
long long flowerGame(int n, int m) { | |
ll count = 0; | |
//Case-1: Odd in N and Even in M | |
int odds_in_n = (n+1)/2; | |
int even_in_m = m/2; | |
count += (1LL * odds_in_n * even_in_m); |
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
// C++: O(M^2 + N^2 + MN) * (log M + log N) Solution | |
class Solution { | |
vector<vector<int>> prefix_sum; | |
void computePrefixSum(vector<vector<int>>& grid){ | |
for(int i=0;i<grid.size();++i){ | |
for(int j=0;j<grid[0].size();++j){ | |
prefix_sum[i+1][j+1] = grid[i][j] + prefix_sum[i+1][j] + prefix_sum[i][j+1] - prefix_sum[i][j]; | |
} | |
} |
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 minimumArea(vector<vector<int>>& grid) { | |
int m = grid.size(); | |
int n = grid[0].size(); | |
int low_x = INT_MAX, high_x = -1; | |
int low_y = INT_MAX, high_y = -1; | |
for(int i=0;i<m;++i){ | |
for(int j=0;j<n;++j){ |
NewerOlder