leetcode

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

commit bc8800af2930d30f827ddc1b7d881ada5d80cd6a
parent 226177df321c7e565875051333a4322b49ddf5b6
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 15 Nov 2023 21:16:50 +0000

Daily Problem

Diffstat:
AProblems/1846.cpp | 17+++++++++++++++++
MREADME.md | 1+
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/Problems/1846.cpp b/Problems/1846.cpp @@ -0,0 +1,17 @@ +class Solution { + public: + int maximumElementAfterDecrementingAndRearranging(const vector<int> &arr) const { + static int count[100001]; + memset(count, 0x00, sizeof(count)); + + const int n = size(arr); + for (const int num : arr) + count[min(num, n)]++; + + int res = 1; + for (int num = 2; num <= n; num++) { + res = min(res + count[num], num); + } + return res; + } +}; diff --git a/README.md b/README.md @@ -742,6 +742,7 @@ for solving problems. | 1833 | Medium | [Maximum Ice Cream Bars](Problems/1833.cpp) | | 1834 | Medium | [Single-Threaded CPU](Problems/1834.cpp) | | 1845 | Medium | [Seat Reservation Manager](Problems/1845.cpp) | +| 1846 | Medium | [Maximum Element After Decreasing and Rearranging](Problems/1846.cpp) | | 1850 | Medium | [Minimum Adjacent Swaps to Reach the Kth Smallest Number](Problems/1850.cpp) | | 1857 | Hard | [Largest Color Value in a Directed Graph](Problems/1857.cpp) | | 1860 | Medium | [Incremental Memory Leak](Problems/1860.cpp) |