Skip to content

Commit

Permalink
solved earliest possible day of full bloom
Browse files Browse the repository at this point in the history
  • Loading branch information
im-sumit committed Oct 29, 2022
1 parent 07a6647 commit 7afb4c5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions solutions/earliest_possible_day_of_full_bloom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// problem link:

#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;

class Solution
{
public:
// write your code here
int earliestFullBloom(vector<int> &plantTime, vector<int> &growTime)
{
vector<pair<int, int>> v;
int n = plantTime.size();
for (int i = 0; i < n; i++)
{
v.push_back({growTime[i] + 1, plantTime[i]});
}
sort(v.begin(), v.end());
int ans = 0;
int cur = 0;
for (int i = n - 1; i >= 0; i--)
{
int gt = v[i].first;
int pt = v[i].second;
ans = max(ans, cur + pt + gt - 1);
// cout << ans << " " << cur << endl;
cur += pt;
}
return ans;
}
};

int main()
{
Solution s;
}

0 comments on commit 7afb4c5

Please sign in to comment.