commit 9123a59902cfb1fef47d1e08205c612b35d2e8b9
parent d6f9f9640685b1981e776c400aa26e1f224064f3
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Fri, 8 Mar 2024 18:20:11 +0000
Daily Problem and 1 Random Problem
Diffstat:
3 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/Problems/3005.cpp b/Problems/3005.cpp
@@ -0,0 +1,17 @@
+class Solution {
+ public:
+ int maxFrequencyElements(const vector<int> &nums) const {
+ static int count[101];
+ memset(count, 0x00, sizeof(count));
+
+ for (const int n : nums)
+ count[n]++;
+
+ int res = 0, maxi = 0;
+ for (int i = 0; i <= 100; i++) {
+ if (count[i] == maxi) res += count[i];
+ if (count[i] > maxi) res = maxi = count[i];
+ }
+ return res;
+ }
+};
diff --git a/Problems/3070.cpp b/Problems/3070.cpp
@@ -0,0 +1,47 @@
+static const auto _ = []() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ cout.tie(NULL);
+ return 0;
+}();
+
+class Solution {
+ public:
+ int countSubmatrices(vector<vector<int>> &grid, int k) const {
+ int n = size(grid), m = size(grid[0]), res = grid[0][0] <= k;
+
+ for (int i = 1, acc = grid[0][0]; i < n; i++) {
+ grid[i][0] = acc += grid[i][0];
+ if (grid[i][0] <= k)
+ res++;
+ else {
+ n = i;
+ break;
+ }
+ }
+
+ for (int j = 1, acc = grid[0][0]; j < m; j++) {
+ grid[0][j] = acc += grid[0][j];
+ if (grid[0][j] <= k)
+ res++;
+ else {
+ m = j;
+ break;
+ }
+ }
+
+ for (int i = 1; i < n; i++) {
+ for (int j = 1; j < m; j++) {
+ grid[i][j] += grid[i - 1][j] + grid[i][j - 1] - grid[i - 1][j - 1];
+ if (grid[i][j] <= k)
+ res++;
+ else {
+ m = j;
+ break;
+ }
+ }
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -1151,7 +1151,9 @@ for solving problems.
| 2966 | Medium | [Divide Array Into Arrays With Max Difference](Problems/2966.cpp) |
| 2971 | Medium | [Find Polygon With the Largest Perimeter](Problems/2971.cpp) |
| 2997 | Medium | [Minimum Number of Operations to Make Array XOR Equal to K](Problems/2997.cpp) |
+| 3005 | Easy | [Count Elements With Maximum Frequency](Problems/3005.cpp) |
| 3015 | Medium | [Count the Number of Houses at a Certain Distance I](Problems/3015.cpp) |
| 3016 | Medium | [Minimum Number of Pushes to Type Word II](Problems/3016.cpp) |
| 3034 | Medium | [Number of Subarrays That Match a Pattern I](Problems/3034.cpp) |
| 3039 | Medium | [Apply Operations to Make String Empty](Problems/3039.cpp) |
+| 3070 | Medium | [Count Submatrices with Top-Left Element and Sum Less Than k](Problems/3070.cpp) |