feat: add task 8
This commit is contained in:
27
task8/main.py
Normal file
27
task8/main.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
from icecream import ic
|
||||||
|
|
||||||
|
|
||||||
|
string: str = input()
|
||||||
|
max_weight = 0
|
||||||
|
|
||||||
|
def calculate_weight(counter: Counter[str], length: int) -> int:
|
||||||
|
max_occurence: int = counter.most_common(1)[0][1]
|
||||||
|
return max_occurence * length
|
||||||
|
|
||||||
|
counter: Counter[str] = Counter()
|
||||||
|
|
||||||
|
for length in range(1, len(string) + 1):
|
||||||
|
counter.clear()
|
||||||
|
counter.update(
|
||||||
|
string[i:i+length] for i in range(len(string) - length + 1)
|
||||||
|
)
|
||||||
|
# ic(counter)
|
||||||
|
max_weight: int = max(
|
||||||
|
max_weight,
|
||||||
|
calculate_weight(counter, length)
|
||||||
|
)
|
||||||
|
ic(max_weight)
|
||||||
|
|
||||||
|
print(max_weight)
|
||||||
Reference in New Issue
Block a user