commit 7457990da896d45e2655a56ebaaa92b8b4117050
parent 6f0cd157d1fba73dbc349061d479a9c34c21984f
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sun, 5 May 2024 19:20:25 +0200
1 Random Problem
Diffstat:
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/Problems/2860.cpp b/Problems/2860.cpp
@@ -0,0 +1,16 @@
+class Solution {
+ public:
+ int countWays(vector<int> &nums) const {
+ sort(begin(nums), end(nums));
+
+ const int n = size(nums);
+ int res = 0, sel = 0;
+ for (int i = 0; i < n - 1; i++) {
+ if (i + 1 <= nums[i]) continue;
+ if (i + 1 < nums[i + 1]) res++;
+ }
+
+ if (n > nums[n - 1]) res++;
+ return res + (nums[0] != 0);
+ }
+};
diff --git a/README.md b/README.md
@@ -1191,6 +1191,7 @@ for solving problems.
| 2840 | Medium | [Check if Strings Can be Made Equal With Operations II](Problems/2840.cpp) |
| 2849 | Medium | [Determine if a Cell Is Reachable at a Given Time](Problems/2849.cpp) |
| 2856 | Medium | [Minimum Array Length After Pair Removals](Problems/2856.cpp) |
+| 2860 | Medium | [Happy Students](Problems/2860.cpp) |
| 2864 | Easy | [Maximum Odd Binary Number](Problems/2864.cpp) |
| 2870 | Medium | [Minimum Number of Operations to Make Array Empty](Problems/2870.cpp) |
| 2895 | Medium | [Minimum Processing Time](Problems/2895.cpp) |