commit 13a3cc7d8a210c47912a3ad5a48a2c4446d17900
parent cee88272e0b4249ea6f6ba87700f3b7f368baed0
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Mon, 6 Nov 2023 21:42:20 +0000
1 Random Problem
Diffstat:
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/Problems/1552.cpp b/Problems/1552.cpp
@@ -0,0 +1,19 @@
+class Solution {
+ public:
+ int maxDistance(vector<int> &position, int m) const {
+ sort(begin(position), end(position));
+ int low = 0, high = position.back() - position.front();
+ while (low <= high) {
+ const int mid = low + (high - low) / 2;
+ int prev = position[0], count = 1;
+ for (int i = 1; i < position.size(); i++) {
+ if (position[i] - prev >= mid) prev = position[i], count++;
+ }
+ if (count >= m)
+ low = mid + 1;
+ else
+ high = mid - 1;
+ }
+ return high;
+ }
+};
diff --git a/README.md b/README.md
@@ -663,6 +663,7 @@ for solving problems.
| 1544 | Easy | [Make The String Great](Problems/1544.cpp) |
| 1547 | Hard | [Minimum Cost to Cut a Stick](Problems/1547.cpp) |
| 1551 | Medium | [Minimum Operations to Make Array Equal](Problems/1551.cpp) |
+| 1552 | Medium | [Magnetic Force Between Two Balls](Problems/1552.cpp) |
| 1557 | Medium | [Minimum Number of Vertices to Reach All Nodes](Problems/1557.cpp) |
| 1558 | Medium | [Minimum Numbers of Function Calls to Make Target Array](Problems/1558.cpp) |
| 1561 | Medium | [Maximum Number of Coins You Can Get](Problems/1561.cpp) |