Skip to content

Commit b1575d8

Browse files
committed
May 13
1 parent 4e5778a commit b1575d8

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

2025-05-May-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
| May 10 | [2918. Minimum Equal Sum of Two Arrays After Replacing Zeros](https://leetcode.com/problems/minimum-equal-sum-of-two-arrays-after-replacing-zeros/) | Medium | Solved |
1717
| May 11 | [1550. Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds/) | Easy | Solved |
1818
| May 12 | [2094. Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers/) | Easy | Solved |
19-
| May 13 | []() | | |
19+
| May 13 | [3335. Total Characters in String After Transformations I](https://leetcode.com/problems/total-characters-in-string-after-transformations-i/) | Medium | Solved |
2020
| May 14 | []() | | |
2121
| May 15 | []() | | |
2222
| May 16 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 4 | 4 | 0 |
44-
| Medium | 6 | 6 | 0 |
44+
| Medium | 7 | 7 | 0 |
4545
| Hard | 2 | 1 | 1 |
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution:
2+
MOD = 10**9 + 7
3+
4+
def lengthAfterTransformations(self, s: str, t: int) -> int:
5+
counts = [0] * 27
6+
for ch in s:
7+
counts[ord(ch) - ord('a')] += 1
8+
for _ in range(t):
9+
for i in range(25, -1, -1):
10+
counts[i + 1] = counts[i]
11+
counts[0] = 0 # reset a
12+
if counts[26]:
13+
# split z into a and b
14+
counts[0] += counts[26] % self.MOD
15+
counts[1] += counts[26] % self.MOD
16+
counts[26] = 0
17+
return sum(counts) % self.MOD
18+
19+
20+
def main():
21+
s = 'abcyy'
22+
t = 2
23+
assert Solution().lengthAfterTransformations(s, t) == 7
24+
25+
s = 'azbk'
26+
t = 1
27+
assert Solution().lengthAfterTransformations(s, t) == 5
28+
29+
30+
if __name__ == '__main__':
31+
main()

0 commit comments

Comments
 (0)