Загрузка...

# 22.06.2025 [2138. Divide a String Into Groups of Size k]

# 22.06.2025
[2138. Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k/description/) easy
[blog post](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k/solutions/6871846/kotlin-rust-by-samoylenkodmitry-ajm8/)
[substack](https://open.substack.com/pub/dmitriisamoilenko/p/22062025-2138-divide-a-string-into?r=2bam17&utm_campaign=post&utm_medium=web&showWelcomeOnShare=true)
[youtube](https://youtu.be/TUiVCSC3H_I)
![1.webp](https://assets.leetcode.com/users/images/902e17b6-fdb5-4b6a-aa22-98cd6f4c7ba3_1750579719.9991503.webp)

#### Join me on Telegram

https://t.me/leetcode_daily_unstoppable/1027

#### Problem TLDR

k-chunked string, filled tail #easy

#### Intuition

Pad then chunk, or chunk then pad. Prefill everything, or write a precise filling code. Great task to learn the language built-ins.

#### Approach

* if you know Kotlin `padEnd` & `chunked` you don't have to think
* Rust doesn't allow `fmt` with dynamic fill character
* `1 + (size - 1) / k` or `(k + size - 1) / k` will pad to `% k`
* Kotln / Java `String` has `CharArray` constructor arguments
* Rust has `resize` to pad-fill a `Vec`

#### Complexity

- Time complexity:
$$O(n)$$

- Space complexity:
$$O(n)$$

#### Code
https://dmitrysamoylenko.com/2023/07/14/leetcode_daily.html

Видео # 22.06.2025 [2138. Divide a String Into Groups of Size k] канала KittyCat, Keyboard and LeetCode
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять