commit 737e888f863b35e7e8384dcc7149ddca6c816b52
parent 6a9ed3ce45dc84c90a35703482b57f9949f78bd9
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Tue, 20 Jun 2023 10:59:10 +0200
Daily Problem
Diffstat:
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/Problems/2090.cpp b/Problems/2090.cpp
@@ -0,0 +1,22 @@
+class Solution {
+public:
+ vector<int> getAverages(const vector<int> &nums, int k) {
+ int n = nums.size();
+ if (n <= 2 * k) return vector<int>(n, -1);
+
+ vector<int> res(n);
+ long long sum = 0;
+ for (int i = 0; i < k; i++) {
+ sum += nums[i] + nums[i + k];
+ res[i] = res[n - k + i] = -1;
+ }
+
+ for (int i = k; i < n - k; i++) {
+ sum += nums[i + k];
+ res[i] = sum / (2 * k + 1);
+ sum -= nums[i - k];
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -291,7 +291,7 @@ for solving problems.
| 0518 | Medium | [Coin Change II](Problems/0518.cpp) |
| 0520 | Easy | [Detect Capital](Problems/0520.cpp) |
| 0530 | Easy | [Minimum Absolute Difference in BST](Problems/0530.cpp) |
-| 0532 | Medium | [K-diff Pairs in an Array](Problems/0532.cpp) |
+| 0535 | Medium | [K-diff Pairs in an Array](Problems/0532.cpp) |
| 0538 | Medium | [Convert BST to Greater Tree](Problems/0538.cpp) |
| 0540 | Medium | [Single Element in a Sorted Array](Problems/0540.cpp) |
| 0542 | Medium | [01 Matrix](Problems/0542.cpp) |
@@ -423,7 +423,7 @@ for solving problems.
| 1140 | Medium | [Stone Game II](Problems/1140.cpp) |
| 1143 | Medium | [Longest Common Subsequence](Problems/1143.cpp) |
| 1146 | Medium | [Snapshot Array](Problems/1146.cpp) |
-| 1161 | Medium | [Maximum Level Sum of a Binary Tree](Problems/1161.cpp) |
+| 1161 | Medium | [Maximum Level Sum of a Binary Tree](Problems/1161.cpp) |
| 1162 | Medium | [As Far from Land as Possible](Problems/1162.cpp) |
| 1187 | Hard | [Make Array Strictly Increasing](Problems/1187.cpp) |
| 1202 | Medium | [Smallest String With Swaps](Problems/1202.cpp) |
@@ -523,6 +523,7 @@ for solving problems.
| 2039 | Medium | [The Time When the Network Becomes Idle](Problems/2039.cpp) |
| 2073 | Easy | [Time Needed to Buy Tickets](Problems/2073.cpp) |
| 2085 | Easy | [Count Common Words With One Occurrence](Problems/2085.cpp) |
+| 2090 | Medium | [K Radius Subarray Averages](Problems/2090.cpp) |
| 2095 | Medium | [Delete the Middle Node of a Linked List](Problems/2095.cpp) |
| 2101 | Medium | [Detonate the Maximum Bombs](Problems/2101.cpp) |
| 2115 | Medium | [Find All Possible Recipes from Given Supplies](Problems/2115.cpp) |
@@ -552,7 +553,7 @@ for solving problems.
| 2336 | Medium | [Smallest Number in Infinite Set](Problems/2336.cpp) |
| 2343 | Medium | [Query Kth Smallest Trimmed Number](Problems/2343.cpp) |
| 2348 | Medium | [Number of Zero-Filled Subarrays](Problems/2348.cpp) |
-| 2352 | Medium | [Equal Row and Column Pairs](Problems/2352.cpp) |
+| 2352 | Medium | [Equal Row and Column Pairs](Problems/2352.cpp) |
| 2359 | Medium | [Find Closest Node to Given Two Nodes](Problems/2359.cpp) |
| 2360 | Hard | [Longest Cycle in a Graph](Problems/2360.cpp) |
| 2368 | Medium | [Reachable Nodes With Restrictions](Problems/2368.cpp) |