LeetCode Entry
3014. Minimum Number of Pushes to Type Word I
Minimum num-phone presses
3014. Minimum Number of Pushes to Type Word I easy substack youtube
https://dmitrysamoylenko.com/leetcode/

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1436
Problem TLDR
Minimum num-phone presses
Intuition
first eight take one click, second eight takes 2 clicks and so on
Approach
- and from thsi derived the math 8(1+2+..len/8) = 8 * (len/8 * (len/8 + 1)/2); plus the leftovers len%8*(len/8 + 1)
Complexity
-
Time complexity: \(O(1)\)
-
Space complexity: \(O(1)\)
Code
fun minimumPushes(w: String) =
w.indices.sumOf { it/8+1 }
pub fn minimum_pushes(w: String) -> i32 {
let k = w.len()/8; ((4*k+w.len()%8)*(k+1)) as _
}
Comments