Skip to content

Commit b34dac8

Browse files
committed
Mar 11
1 parent e5e4324 commit b34dac8

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def numberOfSubstrings(self, s: str) -> int:
3+
n = len(s)
4+
ch_map = {ch: 0 for ch in ['a', 'b', 'c']}
5+
left_ptr = 0
6+
ans = 0
7+
for right_ptr in range(n):
8+
ch_map[s[right_ptr]] += 1
9+
while ch_map['a'] and ch_map['b'] and ch_map['c']:
10+
ans += (n - right_ptr)
11+
ch_map[s[left_ptr]] -= 1
12+
left_ptr += 1
13+
return ans
14+
15+
16+
def main():
17+
s = 'abcabc'
18+
assert Solution().numberOfSubstrings(s) == 10
19+
20+
s = 'aaacb'
21+
assert Solution().numberOfSubstrings(s) == 3
22+
23+
24+
if __name__ == '__main__':
25+
main()

2025-03-March-LeetCoding-Challenge/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
| March 07 | [2523. Closest Prime Numbers in Range](https://leetcode.com/problems/closest-prime-numbers-in-range/) | Medium | Unsolved |
1414
| March 08 | [2379. Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks/) | Easy | Solved |
1515
| March 09 | [3208. Alternating Groups II](https://leetcode.com/problems/alternating-groups-ii/) | Medium | Unsolved |
16-
| March 10 | []() | | |
17-
| March 11 | []() | | |
16+
| March 10 | [3306. Count of Substrings Containing Every Vowel and K Consonants II](https://leetcode.com/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/) | Medium | Unsolved |
17+
| March 11 | [1358. Number of Substrings Containing All Three Characters](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters/) | Medium | Solved |
1818
| March 12 | []() | | |
1919
| March 13 | []() | | |
2020
| March 14 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 4 | 4 | 0 |
44-
| Medium | 5 | 3 | 2 |
44+
| Medium | 7 | 4 | 3 |
4545
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)