Skip to content

Commit

Permalink
"Count Number of Homogenous Substrings" solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelote committed Nov 11, 2023
1 parent a0b8b20 commit 47361c8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/count_number_of_homogenous_substrings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MOD = 10**9 + 7


class Solution:
def countHomogenous(self, s: str) -> int:
result = 0
prev = ""
curr_stack = 1

for x in s:
if x == prev:
curr_stack += 1
else:
curr_stack = 1

result += curr_stack
prev = x

return result % MOD
15 changes: 15 additions & 0 deletions tests/test_count_number_of_homogenous_substrings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from src.count_number_of_homogenous_substrings import Solution


@pytest.mark.parametrize(
"s,expected",
(
("abbcccaa", 13),
("xy", 2),
("zzzzz", 15),
),
)
def test_solution(s, expected):
assert Solution().countHomogenous(s) == expected

0 comments on commit 47361c8

Please sign in to comment.