LeetCode Entry
3016. Minimum Number of Pushes to Type Word II
Minimum old-phone keypresses
3016. Minimum Number of Pushes to Type Word II medium substack youtube
https://dmitrysamoylenko.com/leetcode/

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1437
Problem TLDR
Minimum old-phone keypresses
Intuition
Sort letters by frequencies. Put most frequen on first columns, then on second, third, etc.
Approach
- use chunks or i/8 + 1
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(1)\)
Code
fun minimumPushes(w: String) = w.groupBy{it}.values
.sortedBy{-it.size}.mapIndexed{i,t->(i/8+1)*t.size}.sum()
pub fn minimum_pushes(w: String) -> i32 {
w.bytes().counts().values().sorted().rev()
.zip(8..).map(|(&f, i)| (f * (i / 8)) as i32).sum()
}
Comments