commit 0ff3eded1ba66f25ed63019c11c4c39db6b561cb
parent 78be7ecce3b712b5c46b44565bafe910fb5831b4
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Thu, 5 Oct 2023 14:25:46 +0000
2 Random Problems
Diffstat:
3 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/Problems/1109.cpp b/Problems/1109.cpp
@@ -0,0 +1,18 @@
+class Solution {
+ public:
+ vector<int> corpFlightBookings(const vector<vector<int>> &bookings, int n) {
+ vector<int> res(n + 1, 0);
+
+ for (const auto &booking : bookings) {
+ res[booking[0] - 1] += booking[2];
+ res[booking[1]] -= booking[2];
+ }
+
+ for (int i = 0, acc = 0; i < n; i++) {
+ res[i] = acc += res[i];
+ }
+
+ res.resize(n);
+ return res;
+ }
+};
diff --git a/Problems/1765.cpp b/Problems/1765.cpp
@@ -0,0 +1,35 @@
+class Solution {
+ typedef tuple<int, int> record;
+
+ public:
+ vector<vector<int>> highestPeak(vector<vector<int>> &isWater) {
+ static const int offset[] = {-1, 0, 1, 0, -1};
+ const int n = isWater.size(), m = isWater[0].size();
+
+ queue<record> q;
+ for (int i = 0; i < n; i++) {
+ for (int j = 0; j < m; j++) {
+ if (isWater[i][j])
+ isWater[i][j] = 0, q.push({i, j});
+ else
+ isWater[i][j] = INT_MAX;
+ }
+ }
+
+ while (!q.empty()) {
+ for (int k = q.size(); k > 0; k--) {
+ const auto [i, j] = q.front();
+ q.pop();
+ for (int k = 0; k < 4; k++) {
+ const int x = i + offset[k], y = j + offset[k + 1];
+ if (x < 0 || x >= n || y < 0 || y >= m) continue;
+ if (isWater[x][y] != INT_MAX) continue;
+ isWater[x][y] = isWater[i][j] + 1;
+ q.push({x, y});
+ }
+ }
+ }
+
+ return isWater;
+ }
+};
diff --git a/README.md b/README.md
@@ -517,6 +517,7 @@ for solving problems.
| 1095 | Easy | [Find Numbers with Even Number of Digits](Problems/1095.cpp) |
| 1099 | Easy | [Replace Elements with Greatest Element on Right Side](Problems/1099.cpp) |
| 1104 | Medium | [Path In Zigzag Labelled Binary Tree](Problems/1104.cpp) |
+| 1109 | Medium | [Corporate Flight Bookings](Problems/1109.cpp) |
| 1110 | Medium | [Delete Nodes And Return Forest](Problems/1110.cpp) |
| 1111 | Medium | [Maximum Nesting Depth of Two Valid Parentheses Strings](Problems/1111.cpp) |
| 1123 | Medium | [Lowest Common Ancestor of Deepest Leaves](Problems/1123.cpp) |
@@ -694,6 +695,7 @@ for solving problems.
| 1743 | Medium | [Restore the Array From Adjacent Pairs](Problems/1743.cpp) |
| 1751 | Hard | [Maximum Number of Events That Can Be Attended II](Problems/1751.cpp) |
| 1753 | Medium | [Maximum Score From Removing Stones](Problems/1753.cpp) |
+| 1765 | Medium | [Map of Highest Peak](Problems/1765.cpp) |
| 1768 | Easy | [Merge Strings Alternately](Problems/1768.cpp) |
| 1769 | Medium | [Minimum Number of Operations to Move All Balls to Each Box](Problems/1769.cpp) |
| 1780 | Medium | [Check if Number is a Sum of Powers of Three](Problems/1780.cpp) |