Count and Say
This sequence works like a small word game: each new term describes groups of digits from the previous one. Write a function count_and_say that returns the n-th term of the sequence. The first term is 1, and after that each run of equal digits becomes a pair: how many digits there are and which digit it is. For example, 21 becomes 1211: one 2 and one 1.
Примеры
Ввод
1Вывод
"1"Ввод
2Вывод
"11"Ввод
3Вывод
"21"Нужно реализовать
def count_and_say(n: int) -> str:
Теги
stringsrecursion
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign inVisible tests
1
Input
1Expected
"1"2
Input
2Expected
"11"3
Input
3Expected
"21"4
Input
4Expected
"1211"5
Input
5Expected
"111221"6
Input
6Expected
"312211"Focus radio
Paused · SomaFM · Fluid