leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 73f0ace490b32599c2f8737e9ff2fc0a28eb4054 |
parent | 1976b8dcea2f7605b91c19e274f5ffe283d45a1f |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Sun, 8 Dec 2024 12:26:28 +0100 |
Daily Problem
Diffstat:A | Problems/2054.cpp | | | +++++++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/Problems/2054.cpp b/Problems/2054.cpp
@@ -0,0 +1,25 @@
class Solution {
public:
int maxTwoEvents(const vector<vector<int>> &events) const {
using type_t = tuple<int, int, int>;
vector<type_t> times;
times.reserve(2 * size(events));
for (const auto &e : events) {
times.emplace_back(e[0], 1, e[2]);
times.emplace_back(e[1] + 1, 0, e[2]);
}
sort(begin(times), end(times));
int res = 0, maxi = 0;
for (const auto [time, is_start, val] : times) {
if (is_start)
res = max(res, val + maxi);
else
maxi = max(maxi, val);
}
return res;
}
};
diff --git a/README.md b/README.md
@@ -1181,6 +1181,7 @@ reference and a base for solving problems.
| 2049 | Medium | [Count Nodes With the Highest Score](Problems/2049.cpp) |
| 2050 | Hard | [Parallel Courses III](Problems/2050.cpp) |
| 2053 | Easy | [Kth Distinct String in an Array](Problems/2053.cpp) |
| 2054 | Medium | [Two Best Non-Overlapping Events](Problems/2054.cpp) |
| 2058 | Medium | [Find the Minimum and Maximum Number of Nodes Between Critical Points](Problems/2058.cpp) |
| 2059 | Medium | [Minimum Operations to Convert Number](Problems/2059.cpp) |
| 2063 | Medium | [Vowels of All Substrings](Problems/2063.cpp) |