Skip to content

Instantly share code, notes, and snippets.

View SuryaPratapK's full-sized avatar

Surya Pratap SuryaPratapK

  • Durgapur
View GitHub Profile
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
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;
class Solution {
public:
int maxFreeTime(int eventTime, int k, vector<int>& startTime, vector<int>& endTime) {
if(eventTime>endTime.back()){
startTime.push_back(eventTime);
endTime.push_back(eventTime);
}
int n = startTime.size();
int max_sum = 0;
int win_sum = 0;
class Solution {
vector<vector<int>> mem;
vector<int> next_event;
int n;
int attendEvent(vector<vector<int>>& events,int pos,int k){
if(k==0 or pos>=n)
return 0;
if(mem[pos][k]!=-1)
return mem[pos][k];
class Solution {
public:
int maxEvents(vector<vector<int>>& events) {
sort(events.begin(),events.end());
int n = events.size();
int pos = 0;
int time = 1;
int attended = 0;
priority_queue<int,vector<int>,greater<int>> minheap;
class FindSumPairs {
vector<int> arr1,arr2;
unordered_map<int,int> ele_freq;
public:
FindSumPairs(vector<int>& nums1, vector<int>& nums2) {
arr1 = nums1;
arr2 = nums2;
for(int ele: nums2)
ele_freq[ele]++;
}
class Solution {
int MOD = 1e9+7;
public:
int possibleStringCount(string word, int k) {
//STEP-1: Make runs array
int n = word.size();
vector<int> runs(1,1);
for(int i=1;i<n;++i){
if(word[i]==word[i-1]) runs.back()++;
else runs.push_back(1);
class Solution {
int MOD = 1e9+7;
void precomputePowerOfTwo(vector<int>& power_of_two,int& n){
power_of_two[0]=1;
for(int i=1;i<n;++i)
power_of_two[i] = (power_of_two[i-1]*2LL)%MOD;
}
public:
int numSubseq(vector<int>& nums, int target) {
int n = nums.size();
class Solution {
#define ll long long
public:
char kthCharacter(long long k, vector<int>& operations) {
int count_ops=0;
ll val = k;
while(val>1){
int jumps = ceil(log2(val));
val -= pow(2,jumps-1);
count_ops += operations[jumps-1];
class Solution {
int countSubsequences(const string& s,const string& next){
int i=0;//Index in s
int j=0;//Index in next
int m = next.size();
int subsequence_count = 0;
while(i<s.size()){
if(s[i]==next[j]){
j++;