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 rowSum(vector<vector<int>>& grid,int& row,int& col){ | |
| int rowSum = grid[row][col] + grid[row][col+1] + grid[row][col+2]; | |
| if(rowSum != grid[row+1][col] + grid[row+1][col+1] + grid[row+1][col+2] or | |
| rowSum != grid[row+2][col] + grid[row+2][col+1] + grid[row+2][col+2]) | |
| return -1; | |
| return rowSum; | |
| } | |
| int colSum(vector<vector<int>>& grid,int& row,int& col){ | |
| int colSum = grid[row][col] + grid[row+1][col] + grid[row+2][col]; |
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 { | |
| unordered_map<string,bool> memo; | |
| bool buildPyramid(string& bottom,string curr,int pos,int n,unordered_map<string,vector<char>>& trio){ | |
| if(n==0) return true;//Built Pyramid | |
| if(pos >= n){//Finished current row | |
| if(memo.count(curr)) return memo[curr]; | |
| return memo[curr] = buildPyramid(curr,"",0,n-1,trio); | |
| } | |
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
| //2 Pass: Exact Penalty Solution | |
| class Solution { | |
| public: | |
| int bestClosingTime(string customers) { | |
| int n = customers.size(); | |
| int closed_penalty = 0; | |
| for(int i=0;i<n;++i) | |
| if(customers[i]=='Y') | |
| closed_penalty++; |
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 maximumHappinessSum(vector<int>& happiness, int k) { | |
| ll sum = 0; | |
| priority_queue<int> maxheap(happiness.begin(),happiness.end()); | |
| int decrease = 0; | |
| while(k--){ | |
| sum += maxheap.top(); |
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 Spreadsheet { | |
| using pii = pair<int,int>; | |
| vector<vector<int>> sheet; | |
| pii getRowCol(string cell){ | |
| int pos = 0; | |
| int col = -1; | |
| if(cell[0]>='A' and cell[0]<='Z'){ | |
| col = cell[0]-'A'; | |
| pos++; |
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 TaskManager { | |
| using pii = pair<int,int>; | |
| priority_queue<pii> maxheap; | |
| unordered_map<int,pii> tid_priority_uid; | |
| public: | |
| TaskManager(vector<vector<int>>& tasks) { | |
| for(auto& task: tasks){ | |
| maxheap.push({task[2],task[1]}); | |
| tid_priority_uid[task[1]] = {task[2],task[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 FoodRatings { | |
| #define pis pair<int,string> | |
| struct compare { | |
| bool operator()(const pis& a, const pis& b) const { | |
| if (a.first != b.first) | |
| return a.first < b.first; // higher rating = higher priority | |
| return a.second > b.second; // lexicographically smaller name = higher priority | |
| } | |
| }; |
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 findGCD(int a,int b){ | |
| if(a==0) | |
| return b; | |
| return findGCD(b%a, a); | |
| } | |
| public: | |
| vector<int> replaceNonCoprimes(vector<int>& nums) { | |
| vector<int> st; | |
| int n = nums.size(); |
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 |
NewerOlder