leetcode

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

commit63fa2d04497b88d02d5ab0f2f20e4cfe262918ef
parent336710072102d54d076b0b520d4268bff37dc708
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateSun, 14 Apr 2024 12:59:03 +0200

1 Random Problem

Diffstat:
AProblems/3106.cpp|+++++++++++
MREADME.md|+

2 files changed, 12 insertions(+), 0 deletions(-)


diff --git a/Problems/3106.cpp b/Problems/3106.cpp

@@ -0,0 +1,11 @@

class Solution {
public:
string getSmallestString(string &s, int k) const {
for (int i = 0; i < size(s) && k > 0; ++i) {
int dist = min(s[i] - 'a', 'z' - s[i] + 1);
s[i] = dist <= k ? 'a' : s[i] - k;
k -= dist;
}
return s;
}
};

diff --git a/README.md b/README.md

@@ -1196,3 +1196,4 @@ for solving problems.

| 3070 | Medium | [Count Submatrices with Top-Left Element and Sum Less Than k](Problems/3070.cpp) |
| 3100 | Medium | [Water Bottles II](Problems/3100.cpp) |
| 3101 | Medium | [Count Alternating Subarrays](Problems/3101.cpp) |
| 3106 | Medium | [Lexicographically Smallest String After Operations With Constraint](Problems/3106.cpp) |