# 26.12.2025 [2483. Minimum Penalty for a Shop]
Min close time by customers max volumne #medium #counting
26.12.2025
2483. Minimum Penalty for a Shop medium blog post substack youtube
Join me on Telegram
Problem TLDR
Min close time by customers max volune #medium #counting
Intuition
Track of the customers volune running sum. YN pairs didn’t change the volume.
Approach
‘Y’-’N’=11
baseline can be anything
Complexity
Time complexity: $$O(n)$$
Space complexity: $$O(1)$$
Code
// 19ms
fun bestClosingTime(c: String): Int {
var v = 1337
return (0..c.length).maxBy { v += 2*(c[max(0,it-1)]-'N')/10-1; v }
}
// 0ms
pub fn best_closing_time(c: String) -> i32 {
let mut v = 404;
(0..=c.len()as i32).max_by_key(|&i|{
v += 2 * (c.as_bytes()[0.max(i-1) as usize]==b'Y')as i32-1; (v,-i)
}).unwrap()
}


