commit cee88272e0b4249ea6f6ba87700f3b7f368baed0
parent 5bd65ab9300f70ee922b0baa973adc2b91a19fdf
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sun, 5 Nov 2023 17:18:19 +0000
Daily Problem
Diffstat:
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/Problems/1535.cpp b/Problems/1535.cpp
@@ -0,0 +1,21 @@
+class Solution {
+ public:
+ int getWinner(vector<int> &arr, int k) const {
+ const int n = arr.size();
+ const int maxi = *max_element(begin(arr), end(arr));
+ if (k >= n) return maxi;
+
+ int crnt = arr[0], count = 0;
+ for (int i = 1; i < n; i++) {
+ if (crnt > arr[i])
+ count++;
+ else {
+ crnt = arr[i];
+ count = 1;
+ }
+ if (count == k || crnt == maxi) return crnt;
+ }
+
+ return maxi;
+ }
+};
diff --git a/README.md b/README.md
@@ -658,6 +658,7 @@ for solving problems.
| 1525 | Medium | [Number of Good Ways to Split a String](Problems/1525.cpp) |
| 1529 | Medium | [Minimum Suffix Flips](Problems/1529.cpp) |
| 1530 | Medium | [Number of Good Leaf Nodes Pairs](Problems/1530.cpp) |
+| 1535 | Medium | [Find the Winner of an Array Game](Problems/1535.cpp) |
| 1539 | Easy | [Kth Missing Positive Number](Problems/1539.cpp) |
| 1544 | Easy | [Make The String Great](Problems/1544.cpp) |
| 1547 | Hard | [Minimum Cost to Cut a Stick](Problems/1547.cpp) |