leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 6b6c1a5c2cb2002512755f718ce16e9cdc92dd58
parent a4d87fe1697deeec15446391bafcfd89aa6ded01
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sun,  8 Sep 2024 21:08:10 +0200

1 Random Problem

Diffstat:
AProblems/2100.cpp | 41+++++++++++++++++++++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/Problems/2100.cpp b/Problems/2100.cpp @@ -0,0 +1,41 @@ +class Solution { + public: + vector<int> goodDaysToRobBank(const vector<int> &security, int time) const { + static int up[100001], down[100001]; + const int n = size(security); + + if (time == 0) { + vector<int> res(n); + iota(begin(res), end(res), 0); + return res; + } + + up[0] = down[n - 1] = 0; + for (int i = 0, cnt = 1; i < n - 1; i++) { + if (security[i] >= security[i + 1]) + cnt++; + else + cnt = 0; + up[i + 1] = cnt; + } + + for (int i = n - 1, cnt = 0; i >= 1; i--) { + if (security[i] >= security[i - 1]) + cnt++; + else + cnt = 0; + down[i - 1] = cnt; + } + + vector<int> res; + for (int i = time; i < n - time; i++) { + if (up[i] < time || down[i] < time) continue; + if (security[i] > security[i - 1]) continue; + if (security[i] > security[i + 1]) continue; + + res.emplace_back(i); + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -1093,6 +1093,7 @@ for solving problems. | 2092 | Hard | [Find All People With Secret](Problems/2092.cpp) | | 2095 | Medium | [Delete the Middle Node of a Linked List](Problems/2095.cpp) | | 2096 | Medium | [Step-By-Step Directions From a Binary Tree Node to Another](Problems/2096.cpp) | +| 2100 | Medium | [Find Good Days to Rob the Bank](Problems/2100.cpp) | | 2101 | Medium | [Detonate the Maximum Bombs](Problems/2101.cpp) | | 2104 | Medium | [Sum of Subarray Ranges](Problems/2104.cpp) | | 2108 | Easy | [Find First Palindromic String in the Array](Problems/2108.cpp) |