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++ Implementation | |
class Solution { | |
public: | |
int minimumScore(vector<int>& nums, vector<vector<int>>& edges) { | |
int n = nums.size(); | |
vector<vector<int>> adj(n); | |
// build adjacency | |
for (auto& e : edges) { | |
int u = e[0], v = e[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 { | |
int modify(string pattern,string& s,const int& points){ | |
int n = s.size(); | |
if(n<2) return 0; | |
string new_s; | |
int tot = 0; | |
for(int i=0;i<n;++i){ | |
if(new_s.size() and new_s.back()==pattern[0] and s[i]==pattern[1]){ | |
new_s.pop_back(); |
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 maximumUniqueSubarray(vector<int>& nums) { | |
int left = 0; | |
int right = 0; | |
int n = nums.size(); | |
unordered_map<int,bool> val_idx; | |
int max_sum = INT_MIN; | |
int win_sum = 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 { | |
struct trienode{ | |
string folder; | |
bool remove = false; | |
map<string,trienode*> child; | |
trienode(string folder){ | |
this->folder = folder; | |
} | |
}; | |
void trieInsert(trienode* root,vector<string>& path){ |
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 minimumDifference(vector<int>& nums) { | |
ll n = nums.size(); | |
//Step-1: Build right max_sum from index n/3 to n | |
priority_queue<ll,vector<ll>,greater<ll>> minheap;//Track right N max items | |
ll right_sum = 0; | |
vector<ll> right_maxsum(n,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 maximumLength(vector<int>& nums, int k) { | |
int n = nums.size(); | |
vector<vector<int>> length(k,vector<int>(k)); | |
int max_len = 0; | |
for(int i=0;i<n;++i){ | |
int curr = nums[i]%k; | |
for(int prev=0;prev<k;++prev){ |
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 maximumLength(vector<int>& nums) { | |
int n = nums.size(); | |
int odd_count = nums[0]%2==1; | |
int even_count = nums[0]%2==0; | |
int alternate_count = 1; | |
bool expecting_even = nums[0]&1 ? true : false; | |
/* | |
true: expecting EVEN as next number in sequence |
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
//Recursion: CPP Code | |
class Solution { | |
int n; | |
int min_rounds = INT_MAX; | |
int max_rounds = INT_MIN; | |
void allPossibleMatchups(int mask,int left,int right,int& p1,int& p2,int rounds){ | |
if(left>=right){ | |
//We are done with current round. Goto next round. | |
allPossibleMatchups(mask,0,n-1,p1,p2,rounds+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 | |
#define pli pair<ll,int> | |
public: | |
int mostBooked(int n, vector<vector<int>>& meetings) { | |
sort(meetings.begin(),meetings.end()); | |
priority_queue<pli,vector<pli>,greater<pli>> free_rooms, occupied_rooms; | |
vector<int> freq(n,0); | |
//Initially all rooms are free |
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 pii pair<int,int> | |
int getFreeTimeByRescheduling(int& i,vector<pii>& top3,vector<int>& startTime, vector<int>& endTime){ | |
int last_end = i==0 ? 0 : endTime[i-1]; | |
if((top3[2].first >= endTime[i]-startTime[i]) and (top3[2].second!=i and top3[2].second!=i+1)) | |
return startTime[i+1]-last_end; | |
else if((top3[1].first >= endTime[i]-startTime[i]) and (top3[1].second!=i and top3[1].second!=i+1)) | |
return startTime[i+1]-last_end; | |
else if((top3[0].first >= endTime[i]-startTime[i]) and (top3[0].second!=i and top3[0].second!=i+1)) | |
return startTime[i+1]-last_end; |
NewerOlder