commit 7164935335ae81c4e3a6786178b73f22fa2e997a
parent 4d3cdfcda8d33bc1cbd5b8f37e755f414e9f522b
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sun, 1 Oct 2023 22:49:31 +0000
Improved Daily Problem and 1 Random Problems
Diffstat:
3 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/Problems/0557.cpp b/Problems/0557.cpp
@@ -1,16 +1,15 @@
class Solution {
public:
- string reverseWords(string s) {
- int last = -1;
- for (int k = 0; k <= s.size(); k++) {
- if (k == s.size() || s[k] == ' ') {
- int i = last + 1;
- int j = k - 1;
- while (i < j)
- swap(s[i++], s[j--]);
- last = k;
- }
+ string reverseWords(string &s) {
+ s.push_back(' ');
+ for (int k = 0, last = -1; k <= s.size(); k++) {
+ if (s[k] != ' ') continue;
+ int i = last + 1, j = k - 1;
+ while (i < j)
+ swap(s[i++], s[j--]);
+ last = k;
}
+ s.pop_back();
return s;
}
};
diff --git a/Problems/1738.cpp b/Problems/1738.cpp
@@ -0,0 +1,23 @@
+class Solution {
+ public:
+ int kthLargestValue(const vector<vector<int>> &matrix, int k) {
+ static int crnt[1001], prev[1001];
+ const int n = matrix.size(), m = matrix[0].size();
+ priority_queue<int> pq;
+
+ memset(prev, 0x00, sizeof(prev));
+ for (int i = 0; i < n; i++) {
+ memset(crnt, 0x00, sizeof(crnt));
+ pq.push(crnt[0] = prev[0] ^ matrix[i][0]);
+ for (int j = 1; j < m; j++) {
+ crnt[j] = matrix[i][j] ^ prev[j] ^ crnt[j - 1] ^ prev[j - 1];
+ pq.push(crnt[j]);
+ }
+ swap(prev, crnt);
+ }
+
+ while (--k)
+ pq.pop();
+ return pq.top();
+ }
+};
diff --git a/README.md b/README.md
@@ -326,8 +326,8 @@ for solving problems.
| 0526 | Medium | [Beautiful Arrangement](Problems/0526.cpp) |
| 0529 | Medium | [Minesweeper](Problems/0529.cpp) |
| 0530 | Easy | [Minimum Absolute Difference in BST](Problems/0530.cpp) |
-| 0535 | Medium | [Encode and Decode TinyURL](Problems/0532.cpp) |
-| 0535 | Medium | [K-diff Pairs in an Array](Problems/0532.cpp) |
+| 0532 | Medium | [K-diff Pairs in an Array](Problems/0532.cpp) |
+| 0535 | Medium | [Encode and Decode TinyURL](Problems/0535.cpp) |
| 0537 | Medium | [Complex Number Multiplication](Problems/0537.cpp) |
| 0538 | Medium | [Convert BST to Greater Tree](Problems/0538.cpp) |
| 0540 | Medium | [Single Element in a Sorted Array](Problems/0540.cpp) |
@@ -687,6 +687,7 @@ for solving problems.
| 1727 | Medium | [Largest Submatrix With Rearrangements](Problems/1727.cpp) |
| 1732 | Easy | [Find the Highest Altitude](Problems/1732.cpp) |
| 1734 | Medium | [Decode XORed Permutation](Problems/1734.cpp) |
+| 1738 | Medium | [Find Kth Largest XOR Coordinate Value](Problems/1738.cpp) |
| 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) |