Format the License Key
License keys often contain dashes, but before validation they need to follow one consistent format. The function license_number receives a string key and a group size k. Remove all existing dashes, then regroup the remaining characters from right to left: the first group may be shorter than k, and every other group must have exactly k characters. Preserve the original character order and letter case.
Примеры
Ввод
["a-bc-dfd-df", 1]Вывод
"a-b-c-d-f-d-d-f"Ввод
["a-bc-dfd-df", 2]Вывод
"ab-cd-fd-df"Ввод
["a-bc-dfd-df", 3]Вывод
"ab-cdf-ddf"Нужно реализовать
def license_number(key: str, k: int) -> str:
Теги
strings
Inicia sesión para ver tu historial de envíos
Iniciar sesiónInicia sesión para usar el AI Mentor
Iniciar sesiónVisible tests
1
Input
"a-bc-dfd-df", 1Expected
"a-b-c-d-f-d-d-f"2
Input
"a-bc-dfd-df", 2Expected
"ab-cd-fd-df"3
Input
"a-bc-dfd-df", 3Expected
"ab-cdf-ddf"4
Input
"a-bc-dfd-df", 4Expected
"abcd-fddf"5
Input
"a-bc-dfd-df", 5Expected
"abc-dfddf"6
Input
"a-bc-dfd-dfa-bc-dfd-df", 2Expected
"ab-cd-fd-df-ab-cd-fd-df"Focus radio
Paused · SomaFM · Fluid